Represents a reactive read-write variable that combines getter and setter access with change notifications.
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;
}
}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>
public event Action<T> OnEvent;- Description: Occurs when the signal is emitted with single argument.
- Parameters:
T— the emitted value.
public T Value { get; set; }- Description: Gets or sets the current value.
- Access: Read-write
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>.
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
Valueproperty. - Default implementation comes from IAction<T>.
- Acts as a setter method, complementing the