Search Unity

Feedback Improve creation of custom elements?

Discussion in 'UI Toolkit' started by Crayz, Dec 16, 2020.

  1. Crayz

    Crayz

    Joined:
    Mar 17, 2014
    Posts:
    193
    Hello, I'm curious if there are plans to improve how custom elements are created?

    I have two suggestions:

    1. Remove the need for
    public new class UxmlFactory : UxmlFactory<InventoryGridItem, UxmlTraits> { }


    2. Use attributes for element attributes.

    This:

    Code (csharp):
    1. public new class UxmlTraits : VisualElement.UxmlTraits
    2. {
    3.     UxmlIntAttributeDescription m_Slot = new UxmlIntAttributeDescription() { name = "itemslot" };
    4.     public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc)
    5.     {
    6.         base.Init(ve, bag, cc);
    7.         ((InventoryGridItem)ve).Slot = m_Slot.GetValueFromBag(bag, cc);
    8.     }
    9. }
    Becomes:

    Code (csharp):
    1. [UxmlAttribute(name: "itemslot")]
    2. public int Slot { get; set; }