Skip to content

Latest commit

 

History

History
122 lines (88 loc) · 2.76 KB

File metadata and controls

122 lines (88 loc) · 2.76 KB

🧩 IReactiveVariable<T>

Represents a reactive read-write variable that combines getter and setter access with change notifications.


📑 Table of Contents


🗂 Example of Usage

Below is an example of creating a reactive wrapper around Transform.position

public sealed class ReactiveTransformPosition : IReactiveVariable<Vector3>
{
    public event Action<Vector3> OnValueChanged;
    
    public Vector3 Value
    {
        get => _value;
        set
        {
            if (_value != value)
            {
                _value = value;
                _target.position = value;
                OnValueChanged?.Invoke(value);
            }
        }
    }
    
    private readonly Transform _target;
    private Vector3 _value;

    public ReactiveTransformPosition(Transform target)
    {
        _target = target ?? throw new ArgumentNullException(nameof(target));
        _value = _target.position;
    }
}

🔍 API Reference

🏛️ Type

public interface IReactiveVariable<T> : IVariable<T>, IReactiveValue<T>
  • Description: Represents a reactive read-write variable that combines getter and setter access with change notifications.
  • Inheritance: IVariable<T>, IReactiveValue<T>
  • Type Parameter: T – The type of the value.
  • See also: ReactiveVariable<T>

⚡ Events

OnEvent

public event Action<T> OnEvent;
  • Description: Occurs when the signal is emitted with single argument.
  • Parameters: T — the emitted value.

🔑 Properties

Value

public T Value { get; set; }
  • Description: Gets or sets the current value.
  • Access: Read-write

🏹 Methods

Invoke()

public T Invoke();
  • Description: Invokes the variable and returns its current value.
  • Returns: The current value of type T.
  • Note: Default implementation comes from IFunction<R>.

Invoke(T)

public void Invoke(T arg)
  • Description: Sets the value of the variable to the provided argument.
  • Parameter: arg – The new value to assign to the variable.
  • Notes:
    • Acts as a setter method, complementing the Value property.
    • Default implementation comes from IAction<T>.