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 Inspector
The inspector's help button shows a custom tooltip if there's a Tooltip
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
List |
Constructor. It receives a Serialized |
Fields
inspector |
USS class name of the items in the list. |
item |
USS class name of inspector header buttons. |
item |
USS class name of collapsed inspector headers. |
item |
USS class name of inspector header foldouts. |
item |
USS class name of the inspector header icon. |
item |
USS class name of inspector header labels. |
item |
|
item |
USS class name of the inspector headers. |
uss |
USS class name of elements of this type. |
Methods
Add |
Override this method to customize the header's label. |
Add |
Override this method to add custom menu items to the header's context menu. |
Add |
Override this method to customize the elements after the header's label. |
Add |
Override this method to customize the elements before the header's label. |
Create |
Override this method in a child class to customize inspector headers as a whole. |