docs.unity3d.com
Search Results for

    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
    Assembly: Unity.Localization.dll
    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

    Name Description
    VariableName

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

    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)