Interface IGlobalVariable
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.
Inherited Members
Namespace: UnityEngine.Localization.SmartFormat.GlobalVariables
Assembly: Unity.Localization.dll
Syntax
[Obsolete("Please use UnityEngine.Localization.SmartFormat.PersistentVariables.IVariable instead.")]
public interface IGlobalVariable : 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();
}
}
This shows how to create a custom variable to represent a list of localized strings.
[Serializable]
public class LocalizedStringList : IVariable
{
public List<LocalizedString> localizeds = new List<LocalizedString>();
public object GetSourceValue(ISelectorInfo selector)
{
return localizeds.Select(l => l.GetLocalizedString()).ToList();
}
}