Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

Feature Request TrackedRectTransform should support 3D Position

Discussion in 'Localization Tools' started by lilacsky824, Aug 14, 2021.

  1. lilacsky824

    lilacsky824

    Joined:
    May 19, 2018
    Posts:
    171
    I found some trouble when I use Localized Property Variants.
    I use many of 3d UI object like TextMeshPro's text mesh inside my scene, and I need change text postion when I change localization. So I use Localized Property Variants to do this.
    However current implementation of RectTransform only support 2D position.

    Every-time I change localization will make RectTransform's z position reset to zero at world space position.
    Even I set each localization's local z position to zero, it just go to zero at world space position.
    I am not sure other World space canvas that use RectTransform have similar issue or not.

    I found some workaround is change TrackedRectTransform's source code to use anchoredPosition3D instead of anchoredPosition.

    Like this.
    Code (CSharp):
    1.         ...
    2.         //Change Vector2 to Vector3
    3.         Vector3 m_AnchorPosToApply;
    4.         ...
    5.  
    6.         protected override void AddPropertyHandlers(Dictionary<string, Action<float>> handlers)
    7.         {
    8.             base.AddPropertyHandlers(handlers);
    9.  
    10.             //Change m_AnchoredPosition to m_AnchoredPosition3D and add support for z position
    11.             handlers["m_AnchoredPosition3D.x"] = val => m_AnchorPosToApply.x = val;
    12.             handlers["m_AnchoredPosition3D.y"] = val => m_AnchorPosToApply.y = val;
    13.             handlers["m_AnchoredPosition3D.z"] = val => m_AnchorPosToApply.z = val;
    14.         }
    15.  
    16.         public override AsyncOperationHandle ApplyLocale(Locale variantLocale, Locale defaultLocale)
    17.         {
    18.             var rectTransform = (RectTransform)Target;
    19.             //Change m_AnchoredPosition to m_AnchoredPosition3D for support 3d position
    20.             m_AnchorPosToApply = rectTransform.anchoredPosition3D;
    21.             m_AnchorMinToApply = rectTransform.anchorMin;
    22.             m_AnchorMaxToApply = rectTransform.anchorMax;
    23.             m_PivotToApply = rectTransform.pivot;
    24.             m_SizeDeltaToApply = rectTransform.sizeDelta;
    25.  
    26.             base.ApplyLocale(variantLocale, defaultLocale);
    27.  
    28.             //Change m_AnchoredPosition to m_AnchoredPosition3D for support 3d position
    29.             rectTransform.anchoredPosition3D = m_AnchorPosToApply;
    30.             rectTransform.anchorMin = m_AnchorMinToApply;
    31.             rectTransform.anchorMax = m_AnchorMaxToApply;
    32.             rectTransform.pivot = m_PivotToApply;
    33.             rectTransform.sizeDelta = m_SizeDeltaToApply;
    34.  
    35.             return default;
    36.         }

    I am very like this package, thank you for response. :)
     
    karl_jones likes this.
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,337
    Ah thanks. Could you please file a bug report so we can support this in the future?
     
    lilacsky824 likes this.
  3. lilacsky824

    lilacsky824

    Joined:
    May 19, 2018
    Posts:
    171
    Thank you! :)
    Just send bug report.
    #1358151
     
    karl_jones likes this.