Method Add
Add(string, IVariable)
Adds a new Global Variable to use during formatting.
Declaration
public void Add(string name, IVariable variable)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | The name of the variable, must be unique. Note the name should not contain any whitespace, if any is found then it will be replaced with with '-'. |
| IVariable | variable | The variable to use when formatting. See also BoolVariable, FloatVariable, IntVariable, StringVariable, ObjectVariable. |
Examples
This example shows how to add a variable named "my-int" to a VariablesGroupAsset named "globals".
var source = LocalizationSettings.StringDatabase.SmartFormatter.GetSourceExtension<PersistentVariablesSource>();
var globalVariables = source["globals"];
var intVariable = new IntVariable { Value = 123 };
// This can be accessed from a Smart String with the following syntax: {globals.my-int}
globalVariables.Add("my-int", intVariable);
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown when |
| ArgumentNullException | Thrown when variable is null. |
Add(KeyValuePair<string, IVariable>)
Adds a new Global Variable to use during formatting.
Declaration
public void Add(KeyValuePair<string, IVariable> item)
Parameters
| Type | Name | Description |
|---|---|---|
| KeyValuePair<string, IVariable> | item |