Class TrackedMonoBehaviourObject
Uses JSON to apply variant data to target object.
Implements
Inherited Members
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. |