ReorderableList is not a widely used class in Unity3D, but good use of it can make your custom editor more professional.
This article walks through the typical use of ReorderableList.
- Create a class, let’s call it Country:
- Create a MonoBehaviour class, define a list of Countries in it
- Now create a custom Editor
- Declare a ReorderableList instance (1)
- Associate this instance with the List<Country> SupportedLanguageList instance in previous MonoBehaviour class
- Call the DoLayoutList() function in OnInspectorGUI() function
- Now your UI should look like this:
Now we can do several enhancement upon this default UI:
Add below code in OnEnable function of your custom Editor to fine tune the appearance:
Now your UI should look like this:
Now Let’s change the header of this control:
Now your UI should look like this:
And you have definite unlimited degree to customize this sortable, draggable list!
- It should be note that in your model class (e.g. Country in this case), you must define the exposed field as public field, not a property! Otherwise, when calling
var name = element.FindPropertyRelative(“Name”);
you will get null!
- It should also be note that you should include the namespace:
using UnityEditorInternal;
Filed under: Programming, Unity 3d Tagged: custom editor, drag drop, exmaple, list, ReorderableList, tutorial, Unity, Unity 3d
