Provides a set of interfaces and classes for working with reactive variables, proxy variables, and Unity-specific variable types. It builds on the concept of reactive values but adds more flexibility by allowing variables to act as intermediaries or proxies, which can observe, modify, or synchronize underlying data.
// Create a new variable
IVariable<int> score = new Variable<int>(10);
// Read value
Console.WriteLine(score.Value); // Output: 10
// Write value
score.Value = 20;
Console.WriteLine(score.Value); // Output: 20// Initialize with a starting value
var score = new ReactiveVariable<int>(10);
// Subscribe to changes
score.Subscribe(newValue => Console.WriteLine("Score updated: " + newValue));
// Change the value
score.Value = 20; // Triggers subscription callback
// Dispose to clear subscriptions
score.Dispose();//Create a new proxy of Transform.position
IVariable<Vector3> position = new InlineVariable<Vector3>(
getter: () => transform.position,
setter: value => transform.position = value
);
//Move position:
position.Value += Vector3.forward; - Variables
- ReactiveVariables
- InlineVariables
- Extensions
For convenience, several specialized implementations of base variables are provided. It is recommended to use them, as
they compare values without relying on EqualityComparer, which makes them slightly faster than the generic
Variable<T> version.
- Common
BoolVariable— Boolean variableIntVariable— Integer variableFloatVariable— Float variable
- Unity
QuaternionVariable— Stores a QuaternionVector2Variable— Stores a Vector2Vector3Variable— Stores a Vector3Vector4Variable— Stores a Vector4Vector2IntVariable— Stores a Vector2IntVector3IntVariable— Stores a Vector3Int
- Unity Mathematics
int2_variable— Stores an int2int3_variable— Stores an int3int4_variable— Stores an int4float2_variable— Stores a float2float3_variable— Stores a float3float4_variable— Stores a float4quaternion_variable— Stores a quaternion
For convenience, several specialized implementations of reactive variables are provided. It is recommended to use them,
as they compare values without relying on EqualityComparer, which makes them slightly faster than the generic
ReactiveVariable<T> version.
- Common
ReactiveBool— Boolean reactive variableReactiveInt— Integer reactive variableReactiveFloat— Float reactive variable
- Unity
ReactiveQuaternion— Stores a QuaternionReactiveVector2— Stores a Vector2ReactiveVector3— Stores a Vector3ReactiveVector4— Stores a Vector4ReactiveVector2Int— Stores a Vector2IntReactiveVector3Int— Stores a Vector3Int
- Unity Mathematics
reactive_int2— Stores an int2reactive_int3— Stores an int3reactive_int4— Stores an int4reactive_float2— Stores a float2reactive_float3— Stores a float3reactive_float4— Stores a float4reactive_quaternion— Stores a quaternion
For convenience, several specialized proxy variable implementations are provided.
- Player Prefs
BoolPrefsVariable— Boolean variable stored in PlayerPrefsIntPrefsVariable— Integer variable stored in PlayerPrefsFloatPrefsVariable— Float variable stored in PlayerPrefsStringPrefsVariable— String variable stored in PlayerPrefs
- Transform
TransformParentVariable— Stores a Transform parent referenceTransformPositionVariable— Stores a Vector3 positionTransformRotationVariable— Stores a Quaternion rotationTransformScaleVariable— Stores a Vector3 scale