Click or drag to resize

ObservedValueT Class

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.
Inheritance Hierarchy
SystemObject
  Gamelogic.ExtensionsObservedValueT

Namespace:  Gamelogic.Extensions
Assembly:  Assembly-CSharp (in Assembly-CSharp.dll) Version: 0.0.0.0
Syntax
C#
public class ObservedValue<T>

Type Parameters

T
The type of the value you want to observe

The ObservedValueT type exposes the following members.

Constructors
Properties
  NameDescription
Public propertyValue
Top
Methods
  NameDescription
Public methodEquals (Inherited from Object.)
Protected methodFinalize (Inherited from Object.)
Public methodGetHashCode (Inherited from Object.)
Public methodGetType (Inherited from Object.)
Protected methodMemberwiseClone (Inherited from Object.)
Public methodSetSilently
Sets the value without notification.
Public methodToString (Inherited from Object.)
Top
Events
  NameDescription
Public eventOnValueChange
Subscribe to this event to get notified when the value changes.
Top
Extension Methods
  NameDescription
Public Extension MethodThrowIfNull
Throws a NullReferenceException if the object is null.
(Defined by ObjectExtensions.)
Top
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);
}
See Also