0

Basically, I'd like to make a simple non-scrollable list containing other VisualElements. In order to simplify workflow and allow reusability, I want to make a custom element where I could input an integer for the number of entries in said list in inspector inside UI Builder and have it instantiate rows in the list.

I've written the code for the custom element and the integer in the inspector is showing up correctly.

public class ListElement : VisualElement {

    public new class UxmlFactory : UxmlFactory<ListElement, UxmlTraits> { }

    public new class UxmlTraits : VisualElement.UxmlTraits {
        UxmlIntAttributeDescription _numberOfEntries = new UxmlIntAttributeDescription { name = "Number of entries", defaultValue = 2 };

        public override IEnumerable<UxmlChildElementDescription> uxmlChildElementsDescription {
            get { yield break; }
        }

        public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc) {
            base.Init(ve, bag, cc);
            var ate = ve as ListElement;

            ate.numberOfEntries = _numberOfEntries.GetValueFromBag(bag, cc);
        }
    }
    public int numberOfEntries { get; set; }
}

Now the thing is, I have absolutely no clue how to instantiate the child VisualElements in order for them to show up in the UI Builder. Here is a mockup of what I'd like to achieve.

reck11
  • 1
  • 1

0 Answers0