A wrapper function that easily build ReorderableList for array serailized property in Unity.
ReorderableList is a undocumented editor class that visualize list in UnityEditor.
See this post for more information.
This is build-in array editor
Visualized by Reorderable-list
- Copy /Assets/Editor/ReorderableListUtility.cs into your project
- Create custom editor for your class
- Use example code to build ReorderableList and use it to layout editor
Example editor Assets/Example/Editor/ShopMenuEditor.cs
Note: Test in Unity5.3.5f1
Create ReorderableList
var property = this.serializedObject.FindProperty("MyArrayProperty");
var list = ReorderableListUtility.CreateAutoLayout(property);
Do Layout
// With foldout
ReorderableListUtility.DoLayoutListWithFoldout(list);
// Or original
list.DoLayoutList()
Create ReorderableList with custom headers
var list = ReorderableListUtility.CreateAutoLayout(
property,
new string[] { "Column1", "Column2", "Column3" },
);
Or create ReorderableList with custom column widths
var list = ReorderableListUtility.CreateAutoLayout(
property,
null,
new float?[] { 100, 100, 100 },
);
Or combine them
var list = ReorderableListUtility.CreateAutoLayout(
property,
new string[] { "Column1", "Column2", "Column3" },
new float?[] { 100, 100, 100 },
);
Or specify last column width and auto adject others
var list = ReorderableListUtility.CreateAutoLayout(
property,
new string[] { "Column1", "Column2", "ColumnLast" },
new float?[] { null, null, 100 },
);
This project is licensed under the Apache License - see the LICENSE.md file for details