docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class TrackedRectTransform

    Tracks and applies variant changes to a RectTransform.

    Inheritance
    object
    TrackedObject
    TrackedTransform
    TrackedRectTransform
    Implements
    ISerializationCallbackReceiver
    Inherited Members
    TrackedTransform.CanTrackProperty(string)
    TrackedObject.Target
    TrackedObject.TrackedProperties
    TrackedObject.AddTrackedProperty<T>(string)
    TrackedObject.AddTrackedProperty(ITrackedProperty)
    TrackedObject.RemoveTrackedProperty(ITrackedProperty)
    TrackedObject.GetTrackedProperty<T>(string, bool)
    TrackedObject.GetTrackedProperty(string)
    TrackedObject.CreateCustomTrackedProperty(string)
    TrackedObject.PostApplyTrackedProperties()
    Namespace: UnityEngine.Localization.PropertyVariants.TrackedObjects
    Assembly: Unity.Localization.dll
    Syntax
    [Serializable]
    [DisplayName("Rect Transform", null)]
    [CustomTrackedObject(typeof(RectTransform), false)]
    public class TrackedRectTransform : TrackedTransform, ISerializationCallbackReceiver
    Examples

    This shows how to configure a GameObjectLocalizer to apply changes to a RectTransform for the x, y and width properties. This can be useful when you need to make adjustments due to changes in text length for a particular Locale.

    public class SetupRectTransform : MonoBehaviour
    {
        void Start()
        {
            var localizer = gameObject.AddComponent<GameObjectLocalizer>();
    
            // Gets the Tracked text or creates a new tracker
            var trackedText = localizer.GetTrackedObject<TrackedRectTransform>(transform);
    
            // Gets the Property Variant for the x, y and width
            var xPos = trackedText.GetTrackedProperty<FloatTrackedProperty>("m_AnchoredPosition.x");
            var yPos = trackedText.GetTrackedProperty<FloatTrackedProperty>("m_AnchoredPosition.y");
            var width = trackedText.GetTrackedProperty<FloatTrackedProperty>("m_SizeDelta.x");
    
            xPos.SetValue(LocalizationSettings.ProjectLocale.Identifier, 0); // Default is 0
            xPos.SetValue("ja", 5); // Override for Japanese
    
            yPos.SetValue(LocalizationSettings.ProjectLocale.Identifier, 10); // Default is 10
            yPos.SetValue("fr", 5); // Override for French
    
            width.SetValue(LocalizationSettings.ProjectLocale.Identifier, 100); // Default is 100
            width.SetValue("ja", 50); // Japanese requires less space
            width.SetValue("fr", 150); // French requires more space
    
            // Force an Update
            localizer.ApplyLocaleVariant(LocalizationSettings.SelectedLocale);
        }
    }

    Methods

    Name Description
    AddPropertyHandlers(Dictionary<string, Action<float>>)
    ApplyLocale(Locale, Locale)

    Apply the TrackedProperties for variantLocale. If a value does not exist for this locale then the value for defaultLocale is used as a fallback.

    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)