docs.unity3d.com
    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
    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
    In This Article
    • Methods
      • GetSourceValue(ISelectorInfo)
    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023