Interface IVariable
Represents a variable that can be provided through a global VariablesGroupAsset or as a local variable through LocalizedString instead of as a string format argument. A variable can be a single variable, in which case the value should be returned in GetSourceValue(ISelectorInfo) or a class with multiple variables which can then be further extracted with additional string format arguments.
Namespace: UnityEngine.Localization.SmartFormat.PersistentVariables
Syntax
public interface IVariable
Examples
This shows how to create a custom variable to represent a Date and Time.
[DisplayName("Date Time")]
[Serializable]
public class DateTimeVariable : IVariable
{
[Range(1900, 2050)] public int year;
[Range(0, 12)] public int month;
[Range(0, 31)] public int day;
[Range(0, 24)] public int hour;
[Range(0, 60)] public int min;
[Range(0, 60)] public int sec;
public object GetSourceValue(ISelectorInfo _)
{
try
{
return new DateTime(year, month, day, hour, min, sec);
}
catch
{
// Ignore issues about incorrect values.
}
return new DateTime();
}
}
Methods
GetSourceValue(ISelectorInfo)
The value that will be used when the smart string matches this variable. This value can then be further used by additional sources/formatters.
Declaration
object GetSourceValue(ISelectorInfo selector)
Parameters
Type | Name | Description |
---|---|---|
ISelectorInfo | selector | The details about the current format operation. |
Returns
Type | Description |
---|---|
Object |