private void DrawPropertySortableArray(Rect position, RuntimeSerializedProperty property, GUIContent label) { // Try to get the sortable list this property belongs to RuntimeReorderableListData listData = null; if (listDataDict.Count > 0) { listData = listDataDict.Find(data => property.PropertyPath.StartsWith(data.Parent)); } UnityEditor.Editor scriptableEditor; bool isScriptableEditor = editableDict.TryGetValue(property.PropertyPath, out scriptableEditor); // Has ReorderableList and Try to show the list if (listData != null && listData.DoProperty(position, property)) { } // Else try to draw ScriptableObject editor else if (isScriptableEditor) { bool hasHeader = property.HasAttribute <HeaderAttribute>(); bool hasSpace = property.HasAttribute <SpaceAttribute>(); hasSpace |= hasHeader; // Reference type is not supported! } else { RuntimeEasyGUI.PropertyField(position, property, label, property.IsExpanded, null); } }
private void FindTargetProperties(RuntimeSerializedProperty property) { listDataDict.Clear(); editableDict.Clear(); var depth = property.Depth; do { if (property.IsArray && property.PropertyType != RuntimeSerializedPropertyType.String) { var canTurnToList = property.HasAttribute <ReorderableAttribute>(); if (canTurnToList) { CreateListData(property.RuntimeSerializedObject.FindProperty(property.PropertyPath)); } } if (property.PropertyType.IsSubclassOf(RuntimeSerializedPropertyType.Object)) { var propType = property.GetTypeReflection(); if (propType == null) { continue; } var isScriptable = propType.IsSubclassOf(scriptableObjectType); if (isScriptable) { var makeEditable = property.HasAttribute <ReorderableAttribute>(); if (makeEditable) { UnityEditor.Editor scriptableEditor = null; if (property.ObjectReference != null) { UnityEditor.Editor.CreateCachedEditorWithContext(property.ObjectReference, property.RuntimeSerializedObject.TargetObject, null, ref scriptableEditor); } editableDict.Add(property.PropertyPath, scriptableEditor); } } } } while (property.Depth < depth && property.NextVisible(true)); isInitialized = true; }
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); } } } }