docs.unity3d.com
    Show / Hide Table of Contents

    Class TrackedMonoBehaviourObject

    Uses JSON to apply variant data to target object.

    Inheritance
    Object
    TrackedObject
    JsonSerializerTrackedObject
    TrackedMonoBehaviourObject
    Inherited Members
    JsonSerializerTrackedObject.UpdateType
    JsonSerializerTrackedObject.AddTrackedProperty(ITrackedProperty)
    JsonSerializerTrackedObject.ApplyLocale(Locale, Locale)
    TrackedObject.Target
    TrackedObject.TrackedProperties
    TrackedObject.CanTrackProperty(String)
    TrackedObject.AddTrackedProperty<T>(String)
    TrackedObject.GetTrackedProperty<T>(String, Boolean)
    TrackedObject.GetTrackedProperty(String)
    TrackedObject.CreateCustomTrackedProperty(String)
    Namespace: UnityEngine.Localization.PropertyVariants.TrackedObjects
    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

    Changed

    Declaration
    public UnityEvent Changed { get; }
    Property Value
    Type Description
    UnityEvent

    Methods

    PostApplyTrackedProperties()

    Declaration
    protected override void PostApplyTrackedProperties()
    Overrides
    TrackedObject.PostApplyTrackedProperties()
    Back to top
    Terms of use
    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