docs.unity3d.com

Localization 1.5.1

Search Results for

    Show / Hide Table of Contents

    Class TrackedMonoBehaviourObject

    Uses JSON to apply variant data to target object.

    Inheritance
    object
    TrackedObject
    JsonSerializerTrackedObject
    TrackedMonoBehaviourObject
    Implements
    ISerializationCallbackReceiver
    Inherited Members
    JsonSerializerTrackedObject.UpdateType
    JsonSerializerTrackedObject.AddTrackedProperty(ITrackedProperty)
    JsonSerializerTrackedObject.ApplyLocale(Locale, Locale)
    TrackedObject.Target
    TrackedObject.TrackedProperties
    TrackedObject.CanTrackProperty(string)
    TrackedObject.AddTrackedProperty<T>(string)
    TrackedObject.RemoveTrackedProperty(ITrackedProperty)
    TrackedObject.GetTrackedProperty<T>(string, bool)
    TrackedObject.GetTrackedProperty(string)
    TrackedObject.CreateCustomTrackedProperty(string)
    Namespace: UnityEngine.Localization.PropertyVariants.TrackedObjects
    Assembly: Unity.Localization.dll
    Syntax
    [Serializable]
    [CustomTrackedObject(typeof(MonoBehaviour), true)]
    public class TrackedMonoBehaviourObject : JsonSerializerTrackedObject, ISerializationCallbackReceiver
    Examples

    This shows how to configure a GameObjectLocalizer to apply changes to a custom MonoBehaviour script.

    public class MyScript : MonoBehaviour
    {
        public string myText;
        public Color textColor;
    
        void OnGUI()
        {
            GUI.color = textColor;
            GUILayout.Label(myText);
        }
    }
    
    public static class MyScriptEditor
    {
        public static void SetupLocalization(MyScript script)
        {
            var localizer = script.gameObject.AddComponent<GameObjectLocalizer>();
    
            // Gets the Tracked text or creates a new tracker
            var trackedScript = localizer.GetTrackedObject<TrackedMonoBehaviourObject>(script);
    
            // Gets the Property Variant for the text or creates a new one
            var textVariant = trackedScript.GetTrackedProperty<LocalizedStringProperty>(nameof(MyScript.myText));
            textVariant.LocalizedString.SetReference("My String Table Collection", "My Text");
    
            var redVariant = trackedScript.GetTrackedProperty<FloatTrackedProperty>("textColor.r");
            var greenVariant = trackedScript.GetTrackedProperty<FloatTrackedProperty>("textColor.g");
            var blueVariant = trackedScript.GetTrackedProperty<FloatTrackedProperty>("textColor.b");
    
            // Default to black text
            redVariant.SetValue("en", 0);
            greenVariant.SetValue("en", 0);
            blueVariant.SetValue("en", 0);
    
            // Use Red for French
            redVariant.SetValue("fr", 1);
    
            // Use Green for Japanese
            greenVariant.SetValue("fr", 1);
    
            // Use white for Arabic
            redVariant.SetValue("ar", 1);
            greenVariant.SetValue("ar", 1);
            blueVariant.SetValue("ar", 1);
        }
    }

    Properties

    Name Description
    Changed

    Methods

    Name Description
    PostApplyTrackedProperties()

    Called when the variants have been applied to Target.

    In This Article
    • Properties
    • Methods
    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)