Method TryGetValue
TryGetValue(string, out IVariable)
Gets the IVariable with the specified name.
Declaration
public bool TryGetValue(string name, out IVariable value)
Parameters
Type | Name | Description |
---|---|---|
string | name | The name of the variable. |
IVariable | value | The variable that was found or default. |
Returns
Type | Description |
---|---|
bool |
Implements
Examples
This example shows how to get a variable named "my-float" from a VariablesGroupAsset named "global".
var source = LocalizationSettings.StringDatabase.SmartFormatter.GetSourceExtension<PersistentVariablesSource>();
// If a group called "globals" does not exist then add one.
if (!source.TryGetValue("globals", out var globalVariables))
{
globalVariables = ScriptableObject.CreateInstance<VariablesGroupAsset>();
source.Add("globals", globalVariables);
}
var floatVariable = new FloatVariable { Value = 1.23f };
// This can be accessed from a Smart String with the following syntax: {globals.my-float}
globalVariables.Add("my-float", floatVariable);