Class ObservedValue<T>
- Namespace
- Gamelogic.Extensions
- Assembly
- Gamelogic.Extensions.dll
Wraps a variable in a class that triggers an event if the value changes. This is useful when values can be meaningfully compared using Equals, and when the variable changes infrequently in comparison to the number of times it is updated.
public class ObservedValue<T>
Type Parameters
T
The type of the value you want to observe
- Inheritance
-
ObservedValue<T>
- Inherited Members
- Extension Methods
Remarks
This is a typical use case:
ObservedValue<bool> showWindow;
public void Start()
{
show = new ObservedValue(false);
show.OnValueChanged += ShowHideWindow;
}
public void OnGUI()
{
showWindow.Value = GUILayout.Toggle("Show Window", showWindow.Value);
}
public void ShowHideWindow()
{
window.gameObject.SetActive(showWindow.Value);
}</code></pre>
Constructors
Properties
Methods
- SetSilently(T)
Sets the value without notification.
Events
- OnValueChange
Subscribe to this event to get notified when the value changes.