Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

Bug Official documentation is outdated

Discussion in 'UI Toolkit' started by Kichang-Kim, May 14, 2019.

  1. Kichang-Kim

    Kichang-Kim

    Joined:
    Oct 19, 2010
    Posts:
    498
    Hi, I found that the official documentation for writing custom control is outdated and doesn't work.

    https://docs.unity3d.com/Manual/UIE-UXML.html

    Especially,
    Code (CSharp):
    1. class StatusBar : VisualElement
    2. {
    3.     public class Factory : UxmlFactory<StatusBar, Traits> {}
    4.  
    5.     public class Traits : VisualElement.UxmlTraits
    6.     {
    7.         UxmlStringAttributeDescription m_Status = new UxmlStringAttributeDescription { name = "status" };
    8.        
    9.         public override IEnumerable<UxmlChildElementDescription> uxmlChildElementsDescription
    10.         {
    11.             get { yield break; }
    12.         }
    13.  
    14.         public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc)
    15.         {
    16.             base.Init(ve, bag, cc);
    17.             ((StatusBar)ve).status = m_Status.GetValueFromBag(bag, cc);
    18.         }
    19.     }
    20.  
    21.     // ...
    22. }
    should be fixed to:
    Code (CSharp):
    1. class StatusBar : VisualElement
    2. {
    3.     public new class UxmlFactory : UxmlFactory<StatusBar, Traits> {}
    4.  
    5.     public new class UxmlTraits : VisualElement.UxmlTraits
    6.     {
    7.         UxmlStringAttributeDescription m_Status = new UxmlStringAttributeDescription { name = "status" };
    8.        
    9.         public override IEnumerable<UxmlChildElementDescription> uxmlChildElementsDescription
    10.         {
    11.             get { yield break; }
    12.         }
    13.  
    14.         public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc)
    15.         {
    16.             base.Init(ve, bag, cc);
    17.             ((StatusBar)ve).status = m_Status.GetValueFromBag(bag, cc);
    18.         }
    19.     }
    20.  
    21.     // ...
    22. }
     
  2. patrickf

    patrickf

    Unity Technologies

    Joined:
    Oct 24, 2016
    Posts:
    47
    Thank you!
     
unityunity