public void AddProperty(RuntimeSerializedProperty property) { // Check if this property actually belongs to the same direct child if (!property.GetRootPath().Equals(Parent)) { return; } if (runtimeReorderableListDict.ContainsKey(property.PropertyPath)) { return; } RuntimeReorderableList propList = new RuntimeReorderableList( property.RuntimeSerializedObject.SerializedObject, property, draggable: true, displayHeader: false, displayAddButton: true, displayRemoveButton: true) { headerHeight = 5 }; propList.drawElementBackgroundCallback = (Rect position, int index, bool active, bool focused) => { if (DrawBackgroundCallback != null) { Rect backgroundRect = new Rect(position); if (index <= 0) { backgroundRect.yMin -= 8; } if (index >= propList.count - 1) { backgroundRect.yMax += 3; } EditorGUI.DrawRect(backgroundRect, DrawBackgroundCallback(active, focused)); } else { propList.drawElementBackgroundCallback = null; } }; propList.drawElementCallback = (Rect position, int index, bool active, bool focused) => { var iterProp = property.GetArrayElementAtIndex(index); var elementName = iterProp.DisplayName; if (ElementNameCallback != null) { elementName = ElementNameCallback(index); } RuntimeEasyGUI.PropertyField(position, iterProp, new GUIContent(elementName), ElementAttributes); }; propList.elementHeightCallback = index => ElementHeightCallback(property, index); runtimeReorderableListDict.Add(property.PropertyPath, propList); }
private void CreateListData(RuntimeSerializedProperty property) { var root = property.GetRootPath(); // Try to find the grand parent in RuntimeReorderableListData var data = listDataDict.Find(listData => listData.Parent.Equals(root)); if (data == null) { data = new RuntimeReorderableListData(root); listDataDict.Add(data); } data.AddProperty(property); data.EditableCallback = () => { if (Application.isPlaying && property.HasAttribute <RuntimeObjectAttribute>()) { return(false); } return(true); }; if (property.HasAttribute <ReorderableAttribute>()) { var reorderableAttr = property.GetAttributes <ReorderableAttribute>()[0] as ReorderableAttribute; if (reorderableAttr != null) { HandleReorderableOptions(reorderableAttr, property, data); } } if (property.HasAttribute <BackgroundColorAttribute>()) { var bgColorAttr = property.GetAttributes <BackgroundColorAttribute>()[0] as BackgroundColorAttribute; if (bgColorAttr != null) { HandleBackgroundColorOptions(bgColorAttr, property, data); } } if (property.HasAttribute <DropdownMenuAttribute>()) { var dropDownAttr = property.GetAttributes <DropdownMenuAttribute>()[0] as DropdownMenuAttribute; var reorderableList = data.GetPropertyList(property); reorderableTypeDict.Add(reorderableList, dropDownAttr.Type); reorderableList.onAddDropdownCallback += OnAddDropdownHandler; reorderableList.onRemoveCallback += OnRemoveHandler; } if (property.HasAttribute <PropertyAttribute>()) { foreach (var attr in property.GetAttributes <PropertyAttribute>()) { if (attr is ReorderableAttribute || attr is BackgroundColorAttribute || attr is DropdownMenuAttribute) { } else { data.ElementAttributes.Add(attr as PropertyAttribute); } } } }