Variables API¶
Local Variables¶
Local Name Variables and Local List Variables are components attached to game objects and their value is bound to the scene they are. To access their runtime values you reference the component and call one of their public methods.
Local Name Variables¶
Local Name Variables are components attached to game objects and can be referenced like any other script. To access any of its values you can use the following methods:
Getting values¶
bool Exists(string name)
Returns true if the variable exists. False otherwise
object Get(string name)
Returns the value of the variable. Requires to be casted to the correct value
Setting values¶
void Set(string name, object value)
Sets the value of a variable
Listening to events¶
You can also register when a Local Name Variable changes using the following methods:
void Register(Action<string> callback)
Executes the callback every time a variable changes its value
void Unregister(Action<string> callback)
Stops executing the callback when the variable changes
Local List Variables¶
A Local List Variables component has the following methods for getting and manipulating its values:
Getting values¶
object Get(IListGetPick pick)
Returns the value indexed by the pick parameter
int Count
Property that returns the number of elements of the list
Setting values¶
void Set(IListSetPick pick, object value)
Sets a value indexed by the pick parameter
void Insert(IListGetPick pick, object content)
Inserts a value at the indexed position
void Push(object value)
Adds a new value at the end of the list
void Remove(IListGetPick pick)
Removes the value indexed by the pick parameter
void Clear()
Removes all values from the list
void Move(IListGetPick pickA, IListGetPick pickB)
Moves the value indexed at a position to a new index
Listening to events¶
You can also register when a Local List Variable changes any of its items using the following methods:
void Register(Action<ListVariableRuntime.Change, int> callback)
Executes the callback method whenever there's a change
void Unregister(Action<ListVariableRuntime.Change, int> callback)
Stops executing the callback when the list changes
Global Variables¶
Global Name Variables and Global List Variables are scriptable objects and their runtime value is stored in a separate singleton manager called GlobalNameVariablesManager
and GlobalListVariablesManager
.
Global Name Variables¶
The GlobalNameVariablesManager
has the following methods available:
Getting values¶
bool Exists(GlobalNameVariables asset, string name)
Returns true if the variable exists. False otherwise
object Get(GlobalNameVariables asset, string name)
Returns the value of the variable. Requires to be casted to the correct value
Setting values¶
void Set(GlobalNameVariables asset, string name, object value)
Sets the value of a variable
Listening to events¶
You can also register when a Global Name Variable changes using the following methods:
void Register(GlobalNameVariables asset, Action<string> callback)
Executes the callback every time the variable changes its value
void Unregister(GlobalNameVariables asset, Action<string> callback)
Stops executing the callback when the variable changes
Global List Variables¶
The GlobalListVariablesManager
has the following methods:
Gettings values¶
int Count(GlobalListVariables asset)
Returns the number of elements of the list
object Get(GlobalListVariables asset, IListGetPick pick)
Setting values¶
Returns the value indexed by the pick parameter
void Set(GlobalListVariables asset, IListSetPick pick, object value)
Sets a value indexed by the pick parameter
void Insert(GlobalListVariables asset, IListGetPick pick, TValue content)
Inserts a value at the indexed position
void Push(GlobalListVariables asset, TValue value)
Adds a new value at the end of the list
void Remove(GlobalListVariables asset, IListGetPick pick)
Removes the value indexed by the pick parameter
void Clear(GlobalListVariables asset)
Removes all values from the list
void Move(GlobalListVariables asset, IListGetPick pickA, IListGetPick pickB)
Moves the value indexed at a position to a new index
Listening to events¶
You can also register when a Global List Variable changes any of its items using the following methods:
void Register(GlobalListVariables asset, Action<ListVariableRuntime.Change, int> callback)
Executes the callback method whenever there's a change
void Unregister(GlobalListVariables asset, Action<ListVariableRuntime.Change, int> callback)
Stops executing the callback when the list changes