docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Method Add

    Add(string, IVariable)

    Adds a new Global Variable to use during formatting.

    Declaration
    public void Add(string name, IVariable variable)
    Parameters
    Type Name Description
    string name

    The name of the variable, must be unique. Note the name should not contain any whitespace, if any is found then it will be replaced with with '-'.

    IVariable variable

    The variable to use when formatting. See also BoolVariable, FloatVariable, IntVariable, StringVariable, ObjectVariable.

    Examples

    This example shows how to add a variable named "my-int" to a VariablesGroupAsset named "globals".

    var source = LocalizationSettings.StringDatabase.SmartFormatter.GetSourceExtension<PersistentVariablesSource>();
    
    var globalVariables = source["globals"];
    
    var intVariable = new IntVariable { Value = 123 };
    
    // This can be accessed from a Smart String with the following syntax: {globals.my-int}
    globalVariables.Add("my-int", intVariable);
    Exceptions
    Type Condition
    ArgumentException

    Thrown when name is null or empty.

    ArgumentNullException

    Thrown when variable is null.

    Add(KeyValuePair<string, IVariable>)

    Adds a new Global Variable to use during formatting.

    Declaration
    public void Add(KeyValuePair<string, IVariable> item)
    Parameters
    Type Name Description
    KeyValuePair<string, IVariable> item
    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)