docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    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
    Assembly: Unity.Localization.dll
    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();
        }
    }

    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();
        }
    }

    Methods

    Name Description
    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.

    In This Article
    Back to top
    Copyright © 2024 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)