Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Bug Official documentation is outdated

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

  1. Kichang-Kim

    Kichang-Kim

    Joined:
    Oct 19, 2010
    Posts:
    274
    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:
    43
    Thank you!