Method Add
Add(string, IVariable)
Adds a new Local 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 get and add a local variable.
var localizedString = new LocalizedString("My Table", "My Entry");
// An example of a Smart String using the variable would be: "You have {player-money:C}.".
// :C will apply the current Locale currency and number formatting.
localizedString.Add("player-money", new FloatVariable { Value = 100.45f });
// Get a variable from the localized string
var variable = localizedString["player-money"] as FloatVariable;
Debug.Log("The value is " + variable);
Exceptions
Type | Condition |
---|---|
ArgumentException | Thrown when |
ArgumentNullException | Thrown when variable is null. |
Add(KeyValuePair<string, IVariable>)
Adds a new Local Variable to use during formatting.
Declaration
public void Add(KeyValuePair<string, IVariable> item)
Parameters
Type | Name | Description |
---|---|---|
KeyValuePair<string, IVariable> | item | The local variable name and value to add. |