Class Bindable<T>
- Namespace
- WitShells.DesignPatterns.Core
A reactive property wrapper that automatically fires a UnityEvent<T> whenever its value changes. Use this to implement the Observer / Data-Binding pattern without manual event wiring.
public class Bindable<T>
Type Parameters
TThe type of the wrapped value.
- Inheritance
-
Bindable<T>
- Inherited Members
Examples
var health = new Bindable<int>(100);
health.OnValueChanged.AddListener(v => Debug.Log($"Health changed to {v}"));
health.Value = 50; // fires the event automatically
Constructors
Bindable(T)
Creates a new Bindable<T> with an optional initial value.
public Bindable(T initialValue = default)
Parameters
initialValueTThe starting value. Defaults to
default(T).
Fields
OnValueChanged
Event fired every time Value is assigned a different value.
public UnityEvent<T> OnValueChanged
Field Value
- UnityEvent<T>
Properties
Value
Gets or sets the wrapped value. The setter only fires OnValueChanged when the new value differs from the current one.
public T Value { get; set; }
Property Value
- T