docs.unity3d.com
    Show / Hide Table of Contents

    Interface IMetadataVariable

    Adds support for querying the Metadata in a Smart String.

    Inherited Members
    IVariable.GetSourceValue(ISelectorInfo)
    Namespace: UnityEngine.Localization.SmartFormat.PersistentVariables
    Syntax
    public interface IMetadataVariable : IVariable
    Examples

    In some languages, such as Spanish, all nouns have a gender, that means they are either masculine or feminine. The structure of the sentence will change according to the gender of the item. This example shows how metadata can be used to mark an entry with a gender which can then be queried to create a dynamic string with the correct gender forms. This shows how the following metadata could be used in a Smart String, where item is a LocalizedString local variable: {item.gender:choose(Male|Female):El|La}

        [Metadata(AllowedTypes = MetadataType.StringTableEntry)]
    [Serializable]
    public class ItemGender : IMetadata, IMetadataVariable
    {
        public enum Gender
        {
            None,
            Female,
            Male
        }
    
        public Gender gender = Gender.None;
    
        /// <summary>
        /// The name used to identify this metadata.
        /// </summary>
        public string VariableName => "gender";
    
        public object GetSourceValue(ISelectorInfo _) => gender;
    }

    Properties

    VariableName

    The named placeholder that will match this metdata when querying a LocalizedString as a local or global variable.

    Declaration
    string VariableName { get; }
    Property Value
    Type Description
    String
    In This Article
    • Properties
      • VariableName
    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