private void HandleReorderableOptions(ReorderableAttribute arrayAttr, SerializedProperty property, SortableListData data) { // Custom element header if (string.IsNullOrEmpty(arrayAttr.ElementHeader) == false) { data.ElementHeaderCallback = i => string.Format("{0} {1}", arrayAttr.ElementHeader, (arrayAttr.HeaderZeroIndex ? i : i + 1)); } // Draw property as single line if (arrayAttr.ElementSingleLine) { var list = data.GetPropertyList(property); list.elementHeightCallback = index => EditorGUIUtility.singleLineHeight; list.drawElementCallback = (rect, index, active, focused) => { var element = property.GetArrayElementAtIndex(index); int childCount = element.Copy().CountRemaining(); childCount -= (property.arraySize - 1) - index; if (element.NextVisible(true)) { float restoreWidth = EditorGUIUtility.labelWidth; EditorGUIUtility.labelWidth /= childCount; float padding = 5f; float width = rect.width - padding * (childCount - 1); width /= childCount; Rect childRect = new Rect(rect) { width = width }; int depth = element.Copy().depth; do { if (element.depth != depth) { break; } if (childCount <= 2) { EditorGUI.PropertyField(childRect, element, false); } else { EditorGUI.PropertyField(childRect, element, GUIContent.none, false); } childRect.x += width + padding; } while (element.NextVisible(false)); EditorGUIUtility.labelWidth = restoreWidth; } }; } }
private void CreateListData(SerializedProperty property) { string parent = GetGrandParentPath(property); // Try to find the grand parent in SortableListData SortableListData data = listIndex.Find(listData => listData.Parent.Equals(parent)); if (data == null) { data = new SortableListData(parent); listIndex.Add(data); } data.AddProperty(property); object[] attr = property.GetAttributes <ReorderableAttribute>(); if (attr != null && attr.Length == 1) { ReorderableAttribute arrayAttr = (ReorderableAttribute)attr[0]; if (arrayAttr != null) { HandleReorderableOptions(arrayAttr, property, data); } } }