Overview
Unity package library for sharing variable data across components and scenes, allowing other components to react to changes in values.
Heavily inspired by the infamous Unite 2017: Game Architecture with Scriptable Objects presentation by Ryan Hipple (GitHub).
Unfortunately Unity does not understand generics in the Editor and Inspectors, so only concrete types can be used. Fortunately, this can be made easy by deriving from a single generic type allowing the same common behaviors.
NOTE: This package is still in development and may have breaking changes in future versions until a stable v1.0.0 release is made.
Changelog
All notable changes to this library will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
[0.6.2] - 2022-12-28
Added
ScriptableObjectVariable
variantScriptableObjectWatcher
component- Icons for variables in the Editor
- Icons for watcher components in the Editor
[0.6.1] - 2022-12-08
Fixed
- Missing meta files
[0.6.0] - 2022-12-06
Added
IObservable
interfaceObservableObject
classObservableWatcher
component- Observables sample scene
[0.5.0] - 2022-12-03
Added
ColorVariable
variantColorVariableWatcher
componentColorReference
variantVector2IntVariable
variantVector2IntVariableWatcher
componentVector2IntReference
variantVector2Variable
variantVector2VariableWatcher
componentVector2Reference
variantVector3Variable
variantVector3VariableWatcher
componentVector3Reference
variantVector4Variable
variantVector4VariableWatcher
componentVector4Reference
variantSetPosition(Vector3Variable)
method toTransformVariable
class- Custom editors for new types
Changed
- Exposed
Variable
getter property onRuntimeVariableWatcher
component
[0.4.2] - 2022-12-03
Added
isReadOnly
andIsReadOnly
property toRuntimeVariable
base classMakeReadOnly()
method toRuntimeVariable
base class
[0.4.1] - 2022-12-02
Added
- Docs via
mdbook
inDocumentation~
directory - GitHub CI/CD workflows for documentation
[0.4.0] - 2022-11-30
Added
RuntimeVariableEditor<T>
abstract base classBoolVariableEditor
custom editorDoubleVariableEditor
custom editorFloatVariableEditor
custom editorIntVariableEditor
custom editorStringVariableEditor
custom editorTransformVariableEditor
custom editorRuntimeReferenceDrawer
custom property drawerRuntimeVariableWatcherEditor<T, TVar>
abstract base classBoolVariableWatcherEditor
custom editorDoubleVariableWatcherEditor
custom editorFloatVariableWatcherEditor
custom editorIntVariableWatcherEditor
custom editorStringVariableWatcherEditor
custom editorTransformVariableWatcherEditor
custom editorraiseOnAwake
property toRuntimeVariableWatcher
base class
[0.3.0] - 2022-11-30
Added
RuntimeReference<T>
abstract base classBoolReference
variantDoubleReference
variantFloatReference
variantIntReference
variantStringReference
variantTransformReference
variantCopyFrom(BoolVariable)
method toBoolVariable
CopyFrom(IntVariable)
method toDoubleVariable
CopyFrom(FloatVariable)
method toDoubleVariable
CopyFrom(DoubleVariable)
method toDoubleVariable
CopyFrom(IntVariable)
method toFloatVariable
CopyFrom(FloatVariable)
method toFloatVariable
CopyFrom(IntVariable)
method toIntVariable
CopyFrom(StringVariable)
method toStringVariable
CopyFrom(TransformVariable)
method toTransformVariable
CopyTo(BoolVariable)
method toBoolVariable
CopyTo(DoubleVariable)
method toDoubleVariable
CopyTo(DoubleVariable)
method toFloatVariable
CopyTo(FloatVariable)
method toFloatVariable
CopyTo(IntVariable)
method toIntVariable
CopyTo(FloatVariable)
method toIntVariable
CopyTo(DoubleVariable)
method toIntVariable
CopyTo(StringVariable)
method toStringVariable
CopyTo(TransformVariable)
method toTransformVariable
SetValue(int)
method toDoubleVariable
SetValue(float)
method toDoubleVariable
SetStringValue(int)
method toFloatVariable
Stringify(bool)
method toStringVariable
Stringify(int)
method toStringVariable
Stringify(float)
method toStringVariable
Stringify(double)
method toStringVariable
- References sample scene
Fixed
- Watchers sample scene UI elements
[0.2.1] - 2022-11-30
Changed
- Renamed package to
runtime-variables
- Renamed
Variable<T>
toRuntimeVariable<T>
for consistency - Renamed
VariableWatcher<T>
toRuntimeVariableWatcher<T>
for consistency
[0.2.0] - 2022-11-30
Added
VariableWatcher<T>
abstract base classBoolVariableWatcher
componentDoubleVariableWatcher
componentFloatVariableWatcher
componentIntVariableWatcher
componentStringVariableWatcher
componentTransformVariableWatcher
component- Watchers sample scene
[0.1.0] - 2022-11-29
Added
Variable<T>
abstract base classBoolVariable
variantDoubleVariable
variantFloatVariable
variantIntVariable
variantStringVariable
variantTransformVariable
variant- Variables sample scene
Installation
OpenUPM
OpenUPM is an open source Unity package registry that allows you to easily install thousands of packages.
You can install this library with the following CLI command:
$ openupm add com.underlogic.runtime-variables
Git URL
Starting with Unity 2019.3 you can add packages via git url.
You can add this package by the following url: https://github.com/UnderLogic/runtime-variables
Using this method will allow you to update the package through the Unity Package Manager.
Local Package
Alternatively, you can clone the git repository and add the package locally.
Getting Started
Context
To best understand the purpose of this library and the problems it solves, it is highly recommended to watch the Unite 2017: Game Architecture with Scriptable Objects by Ryan Hipple.
Use Cases
Shared Data
The common case of needing to share data between various components, potentially across multiple scenes. Easy to drag and drop references in the Editor and view/modify them in the Inspector during play mode.
See runtime-collections
library in the related-libraries section for working with collections.
Complex Types
The common case of needing to represent a complex data type with various types of fields. Using the ObservableObject allows property value changes to be seen by other components.
Singleton
The common case of needing a single, global instance of data that can be accessed everywhere. This avoids the common pitfalls of traditional Unity singleton objects.
Event-Based Architecture
The case of only wanting to update or perform actions when necessary (reactively) instead of wastefully computing each frame. This is very common in UI-heavy applications.
See event-channels
library in the related-libraries section for working with an event bus.
Quick Prototyping
The case of being able to swap between constant and variable values on the fly, allowing rapid prototyping and tweaking. By using references you can avoid refactoring components or having to restart your application to test each change.
Samples
The Samples~
folder contains sample scenes showcasing various aspects of the library in action.
It is recommended to import and play around with them in Unity to get a feel for how to use the library.
Custom Types
While this library provides many of the common Unity types you will use, you may want to extend this library with your own custom types specific to your application. Fortunately, this is rather easy and typically only involves creating a derived class from one of the base classes. You may also add any additional helper properties and methods as you need.
Variables
- Create a new class that derives from
RuntimeVariable<T>
, whereT
should be the type you wish to wrap. - Ensure the new type is marked with the
CreateAssetMenu
attribute, so you can create instances in the Editor. - Create any instances of the new variable in your
Assets
folder. - Configure the
isReadOnly
andinitialValue
as needed. - Now you can use them throughout your application.
NOTE: While most people create ScriptableObject
instances in the Editor, you can create them at runtime as well!
Observables
- Create a new class that derives from
ObservableObject
. - Add
private
backing fields andpublic
accessor properties. - Use the
TrySetProperty()
method in the propertyset
block. - Optionally raise events via
RaisePropertyChanged()
method for any computed properties. - Ensure the new type is marked with the
CreateAssetMenu
attribute, so you can create instances in the Editor. - Create any instances of the new variable in your
Assets
folder. - Now you can use them throughout your application.
References
- Create a new class that derives from
RuntimeReference<T, TVar>
whereT
should be the underlying type andTVar
is the variable type. - Ensure the new type is marked with the
Serializable
attribute, so it appears in the Inspector. - Now you can use the reference in your components.
Editor
For the custom Inspector GUI to work you will need to create a new custom property drawer class.
You can reuse the RuntimeReferencePropertyDrawer
class.
- Create a new class that derives from
RuntimeReferenceProperyDrawer
. - Ensure the new class is marked with the
CustomPropertyDrawer
attribute for your custom reference type.
NOTE: You can mark this custom property drawer as the CustomPropertyDrawer
for multiple reference types.
No need to create multiple variants unless you explicitly need them to behave differently.
Watchers
- Create a new class that derives from
RuntimeVariableWatcher<T, TVar>
, whereT
should be the underlying type andTVar
is the variable type. - You can now use the watcher component in your scenes.
Editor
For the custom Inspector GUI to work you will need to create a new custom editor class.
You can reuse the RuntimeVariableWatcherEditor<T, TVar>
class.
- Create a new class that derives from
RuntimeVariableWatcherEditor<T, TVar>
, whereT
should be the underlying type andTVar
is the variable type. - Ensure the new type is marked with the
CustomEditor
attribute for your custom watcher type.
NOTE: Unlike the property drawer, a CustomEditor
can only reference a single type.
You will need to make a custom editor for each custom watcher you make.
Related Libraries
Variables
Overview
Runtime variables are implemented as ScriptableObject
instances that can be used to share their data across components and scenes.
They also provide UnityAction
events when their value changes or is about to be changed.
Many of the variables provide helper mutator methods that make it easier to manipulate their values from other components, including UnityEvent
bindings.
This can be especially useful when using the Watcher components.
RuntimeVariable<T>
Abstract base class that all other runtime variables derive from.
Description
Represents an observable value T
that can be shared and modified throughout the application.
Serialized Fields (Inspector)
isReadOnly : bool
- Whether the variable can be mutated.initialValue : T
- Initial value of the variable, will be re-applied on restart.value : T
- The current value of the variable.
Public Properties
IsReadOnly : bool
(get) - Whether the variable can be mutated.InitialValue : T
(get) - Initial value of the variable, will be re-applied on restart.Value : T
(get, set) - The current value of the variable.
Public Events
ValueChanging : UnityAction<T>
- Raised when the value is about to change, providing the new value to be set.ValueChanged : UnityAction<T>
- Raised when the value has changed, providing the newly set value.
NOTE: These events are only raised when the new value is not equal to the existing value.
Public Methods
GetValue() : T
- Returns the current value of the variable.SetValue(T)
- Sets the value of the variable.SetInitial()
- Sets the value of the variable to the initial value.SetDefault()
- Sets the value of the variable to thedefault(T)
value.MakeReadOnly()
- Marks the variable as readonly, useful for freezing after initialization.RaiseValueChanging(T)
- Manually raises aValueChanging
event with the value provided.RaiseValueChanged()
- Manually raises aValueChanged
event with the current value.
NOTE: Trying to modify a readonly variable will result in an InvalidOperationException
being thrown.
Public Operators
operator RuntimeVariable<T> : T
(implicit) - Allows the variable to be unwrapped to the native typeT
without needing to explicitly cast it.
BoolVariable
Derives from RuntimeVariable<T>
.
Description
Represents an observable bool
value that can be shared and modified throughout the application.
Public Methods
Toggle()
- Inverts the boolean value.CopyFrom(BoolVariable)
- Copies the value of anotherBoolVariable
into this variable.CopyTo(BoolVariable)
- Copies the value from this variable into anotherBoolVariable
.
ColorVariable
Derives from RuntimeVariable<T>
.
Description
Represents an observable Color
value that can be shared and modified throughout the application.
Public Methods
CopyFrom(ColorVariable)
- Copies the value of anotherColorVariable
into this variable.CopyTo(ColorVariable)
- Copies the value from this variable into anotherColorVariable
.
DoubleVariable
Derives from RuntimeVariable<T>
.
Description
Represents an observable double
value that can be shared and modified throughout the application.
Public Methods
Add(int)
- Adds a signedint
value to the variable.Add(float)
- Adds afloat
value to the variable.Add(double)
- Adds adouble
value to the variable.Subtract(int)
- Subtracts a signedint
value from the variable.Subtract(float)
- Subtracts afloat
value from the variable.Subtract(double)
- Subtracts adouble
value from the variable.MultiplyBy(int)
- Multiplies the variable by a signedint
value.MultiplyBy(float)
- Multiplies the variable by afloat
value.MultiplyBy(double)
- Multiplies the variable by adouble
value.DivideBy(int)
- Divides the variable by a signedint
value.DivideBy(float)
- Divides the variable by afloat
value.DivideBy(double)
- Divides the variable by adouble
value.CopyFrom(IntVariable)
- Copies the value of anotherIntVariable
into this variable.CopyFrom(FloatVariable)
- Copies the value of anotherFloatVariable
into this variable.CopyFrom(DoubleVariable)
- Copies the value of anotherDoubleVariable
into this variable.CopyTo(DoubleVariable)
- Copies the value from this variable into anotherDoubleVariable
.SetValue(int)
- Sets the value of this variable to a signedint
value.SetValue(float)
- Sets the value of this variable to afloat
value.
FloatVariable
Derives from RuntimeVariable<T>
.
Description
Represents an observable float
value that can be shared and modified throughout the application.
Public Methods
Add(int)
- Adds a signedint
value to the variable.Add(float)
- Adds afloat
value to the variable.Subtract(int)
- Subtracts a signedint
value from the variable.Subtract(float)
- Subtracts afloat
value from the variable.MultiplyBy(int)
- Multiplies the variable by a signedint
value.MultiplyBy(float)
- Multiplies the variable by afloat
value.DivideBy(int)
- Divides the variable by a signedint
value.DivideBy(float)
- Divides the variable by afloat
value.CopyFrom(IntVariable)
- Copies the value of anotherIntVariable
into this variable.CopyFrom(FloatVariable)
- Copies the value of anotherFloatVariable
into this variable.CopyTo(FloatVariable)
- Copies the value from this variable into anotherFloatVariable
.CopyTo(DoubleVariable)
- Copies the value from this variable into anotherDoubleVariable
.SetValue(int)
- Sets the value of this variable to a signedint
value.
IntVariable
Derives from RuntimeVariable<T>
.
Description
Represents an observable signed int
value that can be shared and modified throughout the application.
Public Methods
Add(int)
- Adds a signedint
value to the variable.Subtract(int)
- Subtracts a signedint
value from the variable.MultiplyBy(int)
- Multiplies the variable by a signedint
value.DivideBy(int)
- Divides the variable by a signedint
value.CopyFrom(IntVariable)
- Copies the value of anotherIntVariable
into this variable.CopyTo(IntVariable)
- Copies the value from this variable into anotherIntVariable
.CopyTo(FloatVariable)
- Copies the value from this variable into anotherFloatVariable
.CopyTo(DoubleVariable)
- Copies the value from this variable into anotherDoubleVariable
.
ScriptableObjectVariable
Derives from RuntimeVariable<T>
.
Description
Represents an observable ScriptableObject
value that can be shared and modified throughout the application.
This component does not have any additional members.
StringVariable
Derives from RuntimeVariable<T>
.
Description
Represents an observable string
value that can be shared and modified throughout the application.
Public Properties
IsNullOrEmpty : bool
(get) - Whether the string isnull
or""
.IsNullOrWhiteSpace : bool
(get) - Whether the string isnull
or whitespace (including empty);
Public Methods
CopyFrom(StringVariable)
- Copies the value of anotherStringVariable
into this variable.CopyTo(StringVariable)
- Copies the value from this variable into anotherStringVariable
.Stringify(bool)
- Sets the value of this variable to the string representation of abool
value.Stringify(int)
- Sets the value of this variable to the string representation of a signedint
value.Stringify(float)
- Sets the value of this variable to the string representation of afloat
value.Stringify(double)
- Sets the value of this variable to the string representation of adouble
value.
NOTE: The Stringify()
methods will format the string using CultureInfo.CurrentCulture
.
TransformVariable
Derives from RuntimeVariable<T>
.
Description
Represents an observable Transform
value that can be shared and modified throughout the application.
Public Methods
SetPosition(Vector3)
- Sets the position of theTransform
to a newVector3
value.SetPosition(Vector3Variable)
- Sets the position of theTransform
to the value of aVector3Variable
.SetActive(bool)
- Sets the active state ofGameObject
of theTransform
.CopyFrom(TransformVariable)
- Copies the value of anotherTransformVariable
into this variable.CopyTo(TransformVariable)
- Copies the value from this variable into anotherTransformVariable
.
Vector2IntVariable
Derives from RuntimeVariable<T>
.
Description
Represents an observable Vector2Int
value that can be shared and modified throughout the application.
Public Methods
CopyFrom(Vector2IntVariable)
- Copies the value of anotherVector2IntVariable
into this variable.CopyTo(Vector2IntVariable)
- Copies the value from this variable into anotherVector2IntVariable
.CopyTo(Vector2Variable)
- Copies the value from this variable into anotherVector2Variable
.CopyTo(Vector3Variable)
- Copies the value from this variable into anotherVector3Variable
.CopyTo(Vector4Variable)
- Copies the value from this variable into anotherVector4Variable
.
Vector2Variable
Derives from RuntimeVariable<T>
.
Description
Represents an observable Vector2
value that can be shared and modified throughout the application.
Public Methods
CopyFrom(Vector2IntVariable)
- Copies the value of anotherVector2IntVariable
into this variable.CopyFrom(Vector2Variable)
- Copies the value of anotherVector2Variable
into this variable.CopyTo(Vector2Variable)
- Copies the value from this variable into anotherVector2Variable
.CopyTo(Vector3Variable)
- Copies the value from this variable into anotherVector3Variable
.CopyTo(Vector4Variable)
- Copies the value from this variable into anotherVector4Variable
.
Vector3Variable
Derives from RuntimeVariable<T>
.
Description
Represents an observable Vector3
value that can be shared and modified throughout the application.
Public Methods
CopyFrom(Vector2IntVariable)
- Copies the value of anotherVector2IntVariable
into this variable.CopyFrom(Vector2Variable)
- Copies the value of anotherVector2Variable
into this variable.CopyFrom(Vector3Variable)
- Copies the value of anotherVector3Variable
into this variable.CopyTo(Vector3Variable)
- Copies the value from this variable into anotherVector3Variable
.CopyTo(Vector4Variable)
- Copies the value from this variable into anotherVector4Variable
.
Vector4Variable
Derives from RuntimeVariable<T>
.
Description
Represents an observable Vector4
value that can be shared and modified throughout the application.
Public Methods
CopyFrom(Vector2IntVariable)
- Copies the value of anotherVector2IntVariable
into this variable.CopyFrom(Vector2Variable)
- Copies the value of anotherVector2Variable
into this variable.CopyFrom(Vector3Variable)
- Copies the value of anotherVector3Variable
into this variable.CopyFrom(Vector4Variable)
- Copies the value of anotherVector4Variable
into this variable.CopyTo(Vector4Variable)
- Copies the value from this variable into anotherVector4Variable
.
Observables
Overview
Observable variables are implemented as ScriptableObject
instances that represent complex data types.
Similar to RuntimeVariable<T>
, they can be used to share their data across components and scenes.
They implement the IObservable
interface which provides UnityAction
events when a property changes.
Usage
Developers are expected to create their own subclasses of ObservableObject
and provide custom properties.
The TrySetProperty<T>()
method handles most of the boilerplate code necessary for automatic notifications of property changes.
Example
public class PlayerData : ObservableObject
{
[SerializeField] private string playerName = "Player";
[SerializeField] private int currentHealth = 50;
[SerializeField] private int maxHealth = 100;
public string PlayerName
{
get => playerName;
set => TrySetProperty(ref playerName, value);
// propertyName will be "PlayerName" automatically via CallerMemberName
// PropertyChanging and PropertyChanged events will be raised
}
public float HealthPercentage => CurrentHealth * 100f / MaxHealth;
public string CurrentHealth
{
get => currentHealth;
set {
// If the current health was changed, notify the computed property changed
if (TrySetProperty(ref currentHealth, value))
RaisePropertyChanged("HealthPercentage");
}
}
public string MaxHealth
{
get => maxHealth;
set {
// If the max health was changed, notify the computed property changed
if (TrySetProperty(ref maxHealth, value))
RaisePropertyChanged("HealthPercentage");
}
}
}
IObservable
Similar to INotifyPropertyChanging
and INotifyPropertyChanged
interfaces.
Description
Represents an object that can be observed for property changes.
Public Events
PropertyChanging : UnityAction<string>
- Raised when a property on the object is about to change, providing the property name.PropertyChanged : UnityAction<string>
- Raised when a property on the object has changed, providing the property name.
Public Methods
RaisePropertyChanging(string)
- Manually raises thePropertyChanging
event with the property name provided.RaisePropertyChanged(string)
- Manually raises thePropertyChanged
event with the property name provided.
ObservableObject
Abstract base class that all other observable objects derive from.
Implements the IObservable
interface.
Description
Represents an object that can be observed for property changes. It can be shared and modified throughout the application.
Public Events
PropertyChanging : UnityAction<string>
- Raised when a property on the object is about to change, providing the property name.PropertyChanged : UnityAction<string>
- Raised when a property on the object has changed, providing the property name.
Public Methods
RaisePropertyChanging(string)
- Manually raises thePropertyChanging
event with the property name provided.RaisePropertyChanged(string)
- Manually raises thePropertyChanged
event with the property name provided.
Protected Methods
TrySetProperty<T>(ref T, T, [string]): bool
- Attempts to set the field value with the newT
value. Optionally, a property name can be provided.
NOTE: The PropertyChanging
and PropertyChanged
events are only raised when the new value is not equal to the existing value.
NOTE: The propertyName
argument is optional and defaults to the value of [CallerMemberName]
.
ObservableWatcher
Base class that all other observable watchers derive from.
Description
Component that watches an ObservableObject
for property changes and raises events.
Serialized Fields (Inspector)
observable : ObservableObject
- The object to watch for property changes.raiseOnAwake : bool
- Whether theonPropertyChanged
event should be raised whenAwake()
is called.raiseOnEnable : bool
- Whether theonPropertyChanged
event should be raised whenOnEnable()
is called.raiseOnStart : bool
- Whether theonPropertyChanged
event should be raised whenStart()
is called.
NOTE: The propertyName
will be null
when the onPropertyChanged
event is raised from raiseOnAwake
, raiseOnEnable
, or raiseOnStart
.
Public Events (Inspector)
onPropertyChanging : UnityEvent<ObservableObject, string>
- The actions to perform when a property on the object is changing.onPropertyChanged : UnityEvent<ObservableObject, string>
- The actions to perform when a property on the object has changed.
Public Properties
Observable : ObservableObject
(get) - The object being watched for property changes.
Public Methods
RaisePropertyChanging(string)
- Manually raises theonPropertyChanging
event with the property name provided.RaisePropertyChanged(string)
- Manually raises theonPropertyChanged
event with the property name provided.
NOTE: Manually raising these events will only trigger the UnityEvent
actions on this component.
References
Overview
References are values that can either point to a constant value or a variable, toggleable at runtime. They are useful when used for quick prototyping and testing of components and features.
Instead of a component needing a constant or hard reference to a RuntimeVariable
, a RuntimeReference
can be used instead.
This allows developers to start with a constant value initially and swap to a variable value without needing to redesign components.
Their main benefit is that they can be switched at runtime which can greatly speed up play-testing and tweaking.
RuntimeReference<T, TVar>
Abstract base class that all other runtime references derive from.
Marked with the Serializable
attribute.
Description
Represents a value that can point to either a constant value T
or RuntimeVariable<T>
value.
Can be toggled at runtime to switch between these values.
Serialized Fields (Inspector)
useConstant : bool
- Whether the reference should point to the constant value or the variable value.constantValue : T
- The constant value to be used, whenuseConstant
istrue
.variable: TVar
- The variable value to be used, whenuseConstant
isfalse
.
Public Properties
UseConstant : bool
- (get, set) - Whether the reference should point to the constant value or the variable value.ConstantValue : T
- (get) - The constant value to be used, whenUseConstant
istrue
.Variable : TVar
(get) - The variable value to be used, whenUseConstant
isfalse
.
Public Methods
GetValue() : T
- Returns the current value, either of the constant value or variable value.SetValue(T)
- Sets the value of the variable to a new value. Has no effect whenUseConstant
istrue
.SetUseConstant(bool)
- Sets whether the reference should point to the constant value or the variable value.
BoolReference
Derives from RuntimeReference<T, TVar>
.
Marked with the Serializable
attribute.
Description
Represents a value that can point to either a constant bool
value or BoolVariable
value.
Can be toggled at runtime to switch between these values.
This class does not have any additional members.
ColorReference
Derives from RuntimeReference<T, TVar>
.
Marked with the Serializable
attribute.
Description
Represents a value that can point to either a constant Color
value or ColorVariable
value.
Can be toggled at runtime to switch between these values.
This class does not have any additional members.
DoubleReference
Derives from RuntimeReference<T, TVar>
.
Marked with the Serializable
attribute.
Description
Represents a value that can point to either a constant double
value or DoubleVariable
value.
Can be toggled at runtime to switch between these values.
This class does not have any additional members.
FloatReference
Derives from RuntimeReference<T, TVar>
.
Marked with the Serializable
attribute.
Description
Represents a value that can point to either a constant float
value or FloatVariable
value.
Can be toggled at runtime to switch between these values.
This class does not have any additional members.
IntReference
Derives from RuntimeReference<T, TVar>
.
Marked with the Serializable
attribute.
Description
Represents a value that can point to either a constant signed int
value or IntVariable
value.
Can be toggled at runtime to switch between these values.
This class does not have any additional members.
StringReference
Derives from RuntimeReference<T, TVar>
.
Marked with the Serializable
attribute.
Description
Represents a value that can point to either a constant string
value or StringVariable
value.
Can be toggled at runtime to switch between these values.
This class does not have any additional members.
TransformReference
Derives from RuntimeReference<T, TVar>
.
Marked with the Serializable
attribute.
Description
Represents a value that can point to either a constant Transform
value or TransformVariable
value.
Can be toggled at runtime to switch between these values.
This class does not have any additional members.
Vector2IntReference
Derives from RuntimeReference<T, TVar>
.
Marked with the Serializable
attribute.
Description
Represents a value that can point to either a constant Vector2Int
value or Vector2IntVariable
value.
Can be toggled at runtime to switch between these values.
This class does not have any additional members.
Vector2Reference
Derives from RuntimeReference<T, TVar>
.
Marked with the Serializable
attribute.
Description
Represents a value that can point to either a constant Vector2
value or Vector2Variable
value.
Can be toggled at runtime to switch between these values.
This class does not have any additional members.
Vector3Reference
Derives from RuntimeReference<T, TVar>
.
Marked with the Serializable
attribute.
Description
Represents a value that can point to either a constant Vector3
value or Vector3Variable
value.
Can be toggled at runtime to switch between these values.
This class does not have any additional members.
Vector4Reference
Derives from RuntimeReference<T, TVar>
.
Marked with the Serializable
attribute.
Description
Represents a value that can point to either a constant Vector4
value or Vector4Variable
value.
Can be toggled at runtime to switch between these values.
This class does not have any additional members.
Watchers
Overview
Runtime variable watchers are implemented as MonoBehaviour
components that can be used to bind UnityEvent
actions to value change events via the Unity Inspector.
This allows the watchers to notify other components without needing to write extra boilerplate code for subscribing and unsubscribing to those events.
It also allows multiple actions to be triggered from a single value change event.
RuntimeVariableWatcher<T, TVar>
Abstract base class that all other runtime variable watchers derive from.
Description
Component that watches a RuntimeVariable<T>
for value changes and raises events.
Serialized Fields (Inspector)
variable : TVar
- The variable to watch for value changes.raiseOnAwake : bool
- Whether theonValueChanged
event should be raised whenAwake()
is called.raiseOnEnable : bool
- Whether theonValueChanged
event should be raised whenOnEnable()
is called.raiseOnStart : bool
- Whether theonValueChanged
event should be raised whenStart()
is called.
Public Events (Inspector)
onValueChanging : UnityEvent<T>
- The actions to perform when the variable value is changing.onValueChanged : UnityEvent<T>
- The actions to perform when the variable value has changed.
Public Properties
Variable : TVar
(get) - The variable being watched for value changes.
Public Methods
RaiseValueChanging(T)
- Manually raises theonValueChanging
event with the value provided.RaiseValueChanged()
- Manually raises theonValueChanged
event with the current value of the variable.
NOTE: Manually raising these events will only trigger the UnityEvent
actions on this component.
BoolVariableWatcher
Derives from RuntimeVariableWatcher<T, TVar>
.
Description
Component that watches a BoolVariable
for value changes and raises events.
This component does not have any additional members.
ColorVariableWatcher
Derives from RuntimeVariableWatcher<T, TVar>
.
Description
Component that watches a ColorVariable
for value changes and raises events.
This component does not have any additional members.
DoubleVariableWatcher
Derives from RuntimeVariableWatcher<T, TVar>
.
Description
Component that watches a DoubleVariable
for value changes and raises events.
This component does not have any additional members.
FloatVariableWatcher
Derives from RuntimeVariableWatcher<T, TVar>
.
Description
Component that watches a FloatVariable
for value changes and raises events.
This component does not have any additional members.
IntVariableWatcher
Derives from RuntimeVariableWatcher<T, TVar>
.
Description
Component that watches a IntVariable
for value changes and raises events.
This component does not have any additional members.
ScriptableObjectVariableWatcher
Derives from RuntimeVariableWatcher<T, TVar>
.
Description
Component that watches a ScriptableObjectVariable
for value changes and raises events.
This component does not have any additional members.
StringVariableWatcher
Derives from RuntimeVariableWatcher<T, TVar>
.
Description
Component that watches a StringVariable
for value changes and raises events.
This component does not have any additional members.
TransformVariableWatcher
Derives from RuntimeVariableWatcher<T, TVar>
.
Description
Component that watches a TransformVariable
for value changes and raises events.
This component does not have any additional members.
Vector2IntVariableWatcher
Derives from RuntimeVariableWatcher<T, TVar>
.
Description
Component that watches a Vector2IntVariable
for value changes and raises events.
This component does not have any additional members.
Vector2VariableWatcher
Derives from RuntimeVariableWatcher<T, TVar>
.
Description
Component that watches a Vector2Variable
for value changes and raises events.
This component does not have any additional members.
Vector3VariableWatcher
Derives from RuntimeVariableWatcher<T, TVar>
.
Description
Component that watches a Vector3Variable
for value changes and raises events.
This component does not have any additional members.
Vector4VariableWatcher
Derives from RuntimeVariableWatcher<T, TVar>
.
Description
Component that watches a Vector4Variable
for value changes and raises events.
This component does not have any additional members.