private void DrawPropertySortableArray(Rect position, InspectableProperty property, GUIContent label) { // Try to get the sortable list this property belongs to ReorderableListData listData = null; if (listIndex.Count > 0) { listData = listIndex.Find(data => property.PropertyPath.StartsWith(data.Parent)); } UnityEditor.Editor scriptableEditor; bool isScriptableEditor = editableIndex.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; // No data in property, draw property field with create button if (scriptableEditor == null) { var fieldPosition = new Rect(position); var buttonPosition = new Rect(position); fieldPosition.width -= hasSpace ? 60 : 50; buttonPosition.xMin = fieldPosition.xMax; EasyGUI.PropertyField(fieldPosition, property); bool doCreate = GUI.Button(buttonPosition, Create, EditorStyles.miniButton); if (doCreate) { var propType = property.GetTypeReflection(); ScriptableObjectUtility.CreateAssetWithSavePrompt(propType, postCreated: createdAsset => { property.ObjectReference = createdAsset; property.IsExpanded = true; return(false); }); } } } else { EasyGUI.PropertyField(position, property, label, property.IsExpanded); } }
private void FindTargetProperties(InspectableProperty property) { listIndex.Clear(); editableIndex.Clear(); var depth = property.Depth; do { if (property.IsArray && property.PropertyType != InspectablePropertyType.String) { var canTurnToList = property.HasAttribute <ReorderableAttribute>(); if (canTurnToList) { CreateListData(property.InspectableObject.FindProperty(property.PropertyPath)); } } if (property.PropertyType.IsSubclassOf(InspectablePropertyType.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.InspectableObject.SerializedObject.targetObject, null, ref scriptableEditor); } editableIndex.Add(property.PropertyPath, scriptableEditor); } } } } while (property.Depth < depth && property.NextVisible(true)); isInitialized = true; }