Class TrackedUGuiGraphic
Uses JSON to apply variant data to UGUI UnityEngine.UI.Graphic instances. Calls UnityEngine.UI.Graphic.SetAllDirty() on the target object after applying changes.
Implements
Inherited Members
Namespace: UnityEngine.Localization.PropertyVariants.TrackedObjects
Assembly: Unity.Localization.dll
Syntax
[Serializable]
[DisplayName("UI Graphic", null)]
[CustomTrackedObject(typeof(Graphic), true)]
public class TrackedUGuiGraphic : JsonSerializerTrackedObject, ISerializationCallbackReceiver
Examples
This shows how to configure a GameObjectLocalizer to apply changes to a Text component for the Font, Font Size and Text properties.
public class SetupTextAndFont : MonoBehaviour
{
public Text text;
void Start()
{
var localizer = gameObject.AddComponent<GameObjectLocalizer>();
// Gets the Tracked text or creates a new tracker
var trackedText = localizer.GetTrackedObject<TrackedUGuiGraphic>(text);
// Gets the Property Variant for the text or creates a new one
var textVariant = trackedText.GetTrackedProperty<LocalizedStringProperty>("m_Text");
// The LocalizedString can be modified directly
textVariant.LocalizedString.SetReference("My String Table", "My Entry");
textVariant.LocalizedString.Arguments = new object[] {"Argument 1", "Argument 2"};
// Set up the Font
var fontVariant = trackedText.GetTrackedProperty<LocalizedAssetProperty>("m_FontData.m_Font");
fontVariant.LocalizedObject = new LocalizedFont { TableReference = "My Assets", TableEntryReference = "My Font" };
// Set up a default Font Size and an override size for French and Japanese. All other Locales will use the default Size.
var fontSize = trackedText.GetTrackedProperty<IntTrackedProperty>("m_FontData.m_FontSize");
fontSize.SetValue(LocalizationSettings.ProjectLocale.Identifier, 10); // Default Font Size
fontSize.SetValue("ja", 12); // Japanese Font Size
fontSize.SetValue("fr", 11); // French Font Size
// Force an Update
localizer.ApplyLocaleVariant(LocalizationSettings.SelectedLocale);
}
}
This shows how to configure a GameObjectLocalizer to apply changes to a TextMeshProUGUI component for the Font, Font Size and Text properties.
public class SetupTmpTextAndFont : MonoBehaviour
{
public TextMeshProUGUI text;
void Start()
{
var localizer = gameObject.AddComponent<GameObjectLocalizer>();
// Gets the Tracked text or creates a new tracker
var trackedText = localizer.GetTrackedObject<TrackedUGuiGraphic>(text);
// Gets the Property Variant for the text or creates a new one
var textVariant = trackedText.GetTrackedProperty<LocalizedStringProperty>("m_text");
// The LocalizedString can be modified directly
textVariant.LocalizedString.SetReference("My String Table", "My Entry");
textVariant.LocalizedString.Arguments = new object[] { "Argument 1", "Argument 2" };
// Set up the Font
var fontVariant = trackedText.GetTrackedProperty<LocalizedAssetProperty>("m_FontData.m_Font");
fontVariant.LocalizedObject = new LocalizedAsset<TMP_FontAsset>() { TableReference = "My Assets", TableEntryReference = "My Font" };
// Set up a default Font Size and an override size for French and Japanese. All other Locales will use the default Size.
var fontSize = trackedText.GetTrackedProperty<IntTrackedProperty>("m_FontData.m_FontSize");
fontSize.SetValue(LocalizationSettings.ProjectLocale.Identifier, 10); // Default Font Size
fontSize.SetValue("ja", 12); // Japanese Font Size
fontSize.SetValue("fr", 11); // French Font Size
// Force an Update
localizer.ApplyLocaleVariant(LocalizationSettings.SelectedLocale);
}
}
Methods
| Name | Description |
|---|---|
| PostApplyTrackedProperties() | Called when the variants have been applied to Target. |