HKI Core
StandardReorderableList.cs
Go to the documentation of this file.
1 using UnityEngine;
2 using UnityEditor;
4 
5 namespace HKI.Core.Editor.Misc
6 {
11  {
12  // Private variables
13  ReorderableList list = null;
14 
15  // Constructor
16  public StandardReorderableList(SerializedObject serializedObject, string propertyName, string label, bool useSelect = true)
17  {
18  list = new ReorderableList(serializedObject, serializedObject.FindProperty(propertyName), true, false, true, true);
19  list.drawHeaderCallback = (Rect rect) =>
20  {
21  EditorGUI.LabelField(rect, label);
22  };
23 
24  list.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) =>
25  {
26  Rect propertyRect = rect;
27  propertyRect.y += 2;
28  propertyRect.height = EditorGUIUtility.singleLineHeight;
29  EditorGUI.PropertyField(propertyRect, list.serializedProperty.GetArrayElementAtIndex(index), GUIContent.none);
30  };
31 
32  if (useSelect)
33  {
34  list.onSelectCallback = (ReorderableList l) =>
35  {
36  Object obj = l.serializedProperty.GetArrayElementAtIndex(l.index).objectReferenceValue;
37  if (obj != null)
38  EditorGUIUtility.PingObject(obj);
39  };
40  }
41  }
42 
43  // Interface function
44  public void DoLayoutList()
45  {
46  list.DoLayoutList();
47  }
48  }
49 }
This class provides you with a better handling of ReorderableList so that ReorderableLists can be use...
StandardReorderableList(SerializedObject serializedObject, string propertyName, string label, bool useSelect=true)