Table of Contents

Class ObservedValue<T>

Namespace
Gamelogic.Extensions
Assembly
Assembly-CSharp.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

ObservedValue(T)

public ObservedValue(T initialValue)

Parameters

initialValue T

Properties

Value

public T Value { get; set; }

Property Value

T

Methods

SetSilently(T)

Sets the value without notification.

public void SetSilently(T value)

Parameters

value T

The value.

Events

OnValueChange

Subscribe to this event to get notified when the value changes.

public event Action OnValueChange

Event Type

Action