Skip to content

Latest commit

 

History

History
115 lines (83 loc) · 2.87 KB

File metadata and controls

115 lines (83 loc) · 2.87 KB

🧩 Variable Extensions

The Extensions class provides utility methods for creating variable wrappers, including standard, reactive, and proxy variables. These methods simplify the creation of variables that support encapsulation, reactivity, and indirect access.


📑 Table of Contents


🗂 Examples of Usage

1️⃣ Using AsVariable()

Variable<int> variable = 42.AsVariable();
Console.WriteLine(variable.Value); // Output: 42

2️⃣ Using AsReactiveVariable()

ReactiveVariable<int> reactiveVariable = 10.AsReactiveVariable();
reactiveVariable.Subscribe(value => Console.WriteLine($"Current value: {value}"));
reactiveVariable.Value = 20; 

// Output:
// Current value: 20

3️⃣ Using AsInlineVariable()

InlineVariable<Vector3> positionProxy = transform.AsInlineVariable(
    getter: t => t.position, 
    setter: (t, value) => t.position = value
);

positionProxy.Value = Vector3.zero;

🔍 API Reference

🏛️ Type

public static class Extensions

🏹 Methods

AsVariable<T>()

public static Variable<T> AsVariable<T>(this T it)
  • Description: Wraps a value in a Variable<T>.
  • Type Parameter: T – The type of the value to wrap
  • Parameter: it – The value to wrap.
  • Returns: A Variable<T> containing the given value.

AsReactiveVariable<T>()

public static ReactiveVariable<T> AsReactiveVariable<T>(this T it)
  • Description: Wraps a value in a ReactiveVariable<T> to support reactive subscriptions.
  • Type Parameter: T – The type of the value to wrap.
  • Parameter: it – The value to wrap.
  • Returns: A ReactiveVariable<T> containing the given value.

AsInlineVariable<T, R>()

public static InlineVariable<R> AsInlineVariable<T, R>(
    this T it,
    Func<T, R> getter,
    Action<T, R> setter
)
  • Description: Creates a InlineVariable<R> that wraps access to a field or property of an object.
  • Type Parameters:
    • T – The type of the source object.
    • R – The type of the value being proxied.
  • Parameters:
    • it – The source object.
    • getter – A function to retrieve the value from the object.
    • setter – An action to set the value on the object.
  • Returns: A InlineVariable<R> that reflects the value through the provided getter and setter.