This packages enables lists that can be nicely displayed in the editor. It's fully extensible.
Contains two implementations:
- UnorderedGameObjectList
- OrderedGameObjectList
Both are very similar, they display a list of game objects, however the ordered one has ordering buttons.
using UnityEditor;
using UnityEngine;
public class MyTestMono : MonoBehaviour
{
public UnorderedGameObjectList GameObjectsList1;
public OrderedGameObjectList GameObjectsList2;
}
// This is required to enable the use of GUILayout. Can also be put in own file.
#if UNITY_EDITOR
[CustomEditor(typeof(MyTestMono)), CanEditMultipleObjects]
public class MyTestMonoCI : Editor{}
#endif
This should give you something similar to:
Implement as above but define your own EditList and ObjectListDrawer. T Must derive from UnityEngine.Object.
using System;
using UnityEngine;
using Sibz.EditorList;
[Serializable]
public class OrderedColliderList : EditorList<Collider> { }
using Sibz.EditorList.Editor;
using UnityEditor;
[CustomPropertyDrawer(typeof(OrderedColliderList))]
public class OrderedColliderListDrawer : ObjectListDrawer<Collider> { }
Anything can be listed, you either have to write a custom property drawer for the object you are listing, or override the default ListView.
- If you made your CustomPropertyDrawer for the property on the list:
[Serializable]
public class CustomObject {
public string Name;
};
[Serializable]
public class OrderedCustomObjectList : EditorList<CustomObject> { }
Note overriding ListDrawer here (not ObjectListDrawer):
[CustomPropertyDrawer(typeof(OrderedCustomObjectList))]
public class CustomObjectListDrawer : ListDrawer<CustomObject> { }
- If you want to do your own thing for the item, then you have to override ListDrawer.ListItemDrawer:
[CustomPropertyDrawer(typeof(OrderedCustomObjectList))]
public class CustomObjectListDrawer : ListDrawer<CustomObject>
{
protected override void ListItemDrawer(SerializedProperty listProperty, SerializedProperty listItemProperty, int index)
{
EditorGUILayout.LabelField(listItemProperty.FindPropertyRelative("Name").stringValue);
}
}
Custom List Result: