ListOfInspectors Class

Description

A list of Objects similar to the components list in a GameObject's inspector.

public class ListOfInspectors : ListControl, IEventHandler, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, IResolvedStyle
Inheritance
Remarks

This element is typically used with a list of subassets. Subasset systems require code that's outside the scope of this package. You may be better off using InspectorElement if you just want to embed inspectors from different Objects.

The inspector's help button shows a custom tooltip if there's a TooltipAttribute in the Object's class. By default, the inspector's header has an EditableLabel for changing the Object's name. More customizations are available by creating a child class. Multitarget SerializedObjects and Editors aren't supported.

Inspectors will try to show special UI when an Object's script is missing. To support this, Unity needs the base type of the Object array/list to be creatable (i.e. not abstract nor generic).

Examples

class CustomEditorWithListOfInspectors : Editor
{
    public override VisualElement CreateInspectorGUI()
    {
        var root = new VisualElement();

        // The mylistOfObjects field should be a list or array of elements that
        // derive from UnityEngine.Object. It's usually a list of ScriptableObjects
        // embedded as subassets in the field's owner.
        var listOfObjectsProperty = serializedObject.FindProperty("mylistOfObjects");
        var listOfInspectors = new MyListOfInspectors(listOfObjectsProperty);
        root.Add(listOfInspectors);

        return root;
    }
}

// Creating a child class of ListOfInspectors allows for some customization:
class MyListOfInspectors : ListOfInspectors
{
    public MyListOfInspectors(SerializedProperty arrayProp) : base(arrayProp) { }

    // Override this method to add elements to an inspector header before its label.
    protected override void AddPrelabelHeaderElements(
        VisualElement header,
        int itemIndex,
        SerializedObject serializedObject)
    {
        base.AddPrelabelHeaderElements(header, itemIndex, serializedObject);
    }

    // Override this method to change how a label is added to an inspector header.
    // The base implementation adds an editable label for changing the object's name.
    protected override void AddHeaderLabel(
        VisualElement header,
        int itemIndex,
        SerializedObject serializedObject)
    {
        base.AddHeaderLabel(header, itemIndex, serializedObject);
    }

    // Override this method to add elements to an inspector header after its label.
    protected override void AddPostlabelHeaderElements(
        VisualElement header,
        int itemIndex,
        SerializedObject serializedObject)
    {
        base.AddPostlabelHeaderElements(header, itemIndex, serializedObject);
    }

    // Override this method to add context menu items for an inspector header.
    protected override void AddItemsToContextMenu(
        GenericMenu menu,
        VisualElement header,
        int itemIndex,
        SerializedObject serializedObject)
    {
        base.AddItemsToContextMenu(menu, header, itemIndex, serializedObject);
        menu.AddItem(new GUIContent("My Menu Item"), true, () =>
        {
            // Do something.
        });
    }
}

Constructors

ListOfInspectors(SerializedProperty)

Constructor. It receives a SerializedProperty for an array or a list of Objects with a type derived from UnityEngine.Object.

Fields

inspectorItemUssClassName

USS class name of the items in the list.

itemHeaderButtonUssClassName

USS class name of inspector header buttons.

itemHeaderCollapsedUssClassName

USS class name of collapsed inspector headers.

itemHeaderFoldoutUssClassName

USS class name of inspector header foldouts.

itemHeaderIconUssClassName

USS class name of the inspector header icon.

itemHeaderLabelUssClassName

USS class name of inspector header labels.

itemHeaderTooltipUssClassName
itemHeaderUssClassName

USS class name of the inspector headers.

ussClassName

USS class name of elements of this type.

Methods

AddHeaderLabel(VisualElement, Int32, SerializedObject)

Override this method to customize the header's label.

AddItemsToContextMenu(GenericMenu, VisualElement, Int32, SerializedObject)

Override this method to add custom menu items to the header's context menu.

AddPostlabelHeaderElements(VisualElement, Int32, SerializedObject)

Override this method to customize the elements after the header's label.

AddPrelabelHeaderElements(VisualElement, Int32, SerializedObject)

Override this method to customize the elements before the header's label.

CreateHeader(Int32, SerializedObject, InspectorElement)

Override this method in a child class to customize inspector headers as a whole.

Inherited Members

ListControl.boxedUssClassName
ListControl.foldedUssClassName
ListControl.withHeaderUssClassName
ListControl.withFooterUssClassName
ListControl.draggingListUssClassName
ListControl.emptyUssClassName
ListControl.dropIndicatorUssClassName
ListControl.emptyMessageUssClassName
ListControl.headerUssClassName
ListControl.footerUssClassName
ListControl.itemUssClassName
ListControl.draggedItemUssClassName
ListControl.selectedItemUssClassName
ListControl.supportItemSelection
ListControl.selectedItem
ListControl.emptyListMessage
ListControl.boxed
ListControl.StartDraggingItem(Int32)
ListControl.GetListSize()
ListControl.SetListSize(Int32)
ListControl.GetListItem(Int32)
ListControl.SetHeaderVisibility(Boolean)
ListControl.SetHeaderContent(VisualElement)
ListControl.SetFooterVisibility(Boolean)
ListControl.SetFooterContent(VisualElement)
ListControl.CreateItemForIndex(Int32)
ListControl.IsReorderable()
ListControl.OnReorderDragPerformed(Int32, Int32)
ListControl.VerifyCustomDrag(Int32)
ListControl.OnCustomDragPerformed(Int32)

Extension Methods

UIToolkitExtensions.GetLocalRect(VisualElement)
UIToolkitExtensions.GetChildren<TElement>(VisualElement, List<TElement>, Func<TElement, Boolean>)
UIToolkitExtensions.GetFirstChild<TElement>(VisualElement, Func<TElement, Boolean>)
UIToolkitExtensions.ForEachChild<TElement>(VisualElement, Action<TElement>)