Просмотр исходного кода

Expanding/collapsing objects inside a GUI array/list now works properly

BearishSun 10 лет назад
Родитель
Сommit
3bf109abe1

+ 17 - 6
MBansheeEditor/GUI/GUIListField.cs

@@ -439,6 +439,9 @@ namespace BansheeEditor
     public abstract class GUIListFieldRow
     {
         private GUILayoutX rowLayout;
+        private GUILayoutY contentLayout;
+        private GUILayoutX titleLayout;
+        private bool localTitleLayout;
         private GUIListFieldBase parent;
 
         protected int seqIndex;
@@ -464,21 +467,29 @@ namespace BansheeEditor
 
             if (rowLayout == null)
                 rowLayout = parentLayout.AddLayoutX();
-            else
-                rowLayout.Clear();
 
-            GUILayoutY contentLayout = rowLayout.AddLayoutY();
+            if (contentLayout == null)
+                contentLayout = rowLayout.AddLayoutY();
 
-            GUILayoutX titleLayout = CreateGUI(contentLayout);
+            GUILayoutX externalTitleLayout = CreateGUI(contentLayout);
+            if (localTitleLayout || titleLayout == externalTitleLayout)
+                return;
 
-            if (titleLayout == null)
+            if (externalTitleLayout != null)
+            {
+                localTitleLayout = false;
+                titleLayout = externalTitleLayout;
+            }
+            else
             {
                 GUILayoutY buttonCenter = rowLayout.AddLayoutY();
                 buttonCenter.AddFlexibleSpace();
                 titleLayout = buttonCenter.AddLayoutX();
                 buttonCenter.AddFlexibleSpace();
-            }
 
+                localTitleLayout = true;
+            }
+            
             GUIContent cloneIcon = new GUIContent(EditorBuiltin.GetInspectorWindowIcon(InspectorWindowIcon.Clone));
             GUIContent deleteIcon = new GUIContent(EditorBuiltin.GetInspectorWindowIcon(InspectorWindowIcon.Delete));
             GUIContent moveUp = new GUIContent(EditorBuiltin.GetInspectorWindowIcon(InspectorWindowIcon.MoveUp));

+ 25 - 17
MBansheeEditor/Inspector/InspectableArray.cs

@@ -53,7 +53,13 @@ namespace BansheeEditor
         /// <inheritdoc/>
         public override bool Refresh(int layoutIndex)
         {
-            bool anythingModified = IsModified();
+            bool anythingModified = false;
+
+            if (IsModified())
+            {
+                Update(layoutIndex);
+                anythingModified = true;
+            }
 
             anythingModified |= arrayGUIField.Refresh();
             return anythingModified;
@@ -96,6 +102,15 @@ namespace BansheeEditor
         {
             private SerializableProperty property;
 
+            /// <summary>
+            /// Constructs an inspectable array GUI.
+            /// </summary>
+            /// <param name="property">Serializable property referencing a single-dimensional array.</param>
+            private InspectableArrayGUI(SerializableProperty property)
+            {
+                this.property = property;
+            }
+
             /// <summary>
             /// Creates a new inspectable GUI array.
             /// </summary>
@@ -105,7 +120,7 @@ namespace BansheeEditor
             /// <returns>Newly created inspectable GUI array object.</returns>
             public static InspectableArrayGUI Create(LocString title, SerializableProperty property, GUILayout layout)
             {
-                InspectableArrayGUI newArrayField = new InspectableArrayGUI();
+                InspectableArrayGUI newArrayField = new InspectableArrayGUI(property);
 
                 object propertyValue = property.GetValue<object>();
                 if (propertyValue != null)
@@ -116,8 +131,6 @@ namespace BansheeEditor
                 else
                     newArrayField.Construct<InspectableArrayGUIRow>(title, true, 0, layout);
 
-                newArrayField.property = property;
-
                 return newArrayField;
             }
 
@@ -250,10 +263,13 @@ namespace BansheeEditor
             /// <inheritdoc/>
             protected override GUILayoutX CreateGUI(GUILayoutY layout)
             {
-                SerializableProperty property = GetValue<SerializableProperty>();
+                if (field == null)
+                {
+                    SerializableProperty property = GetValue<SerializableProperty>();
 
-                field = CreateInspectable(seqIndex + ".", 0, 0,
-                    new InspectableFieldLayout(layout), property);
+                    field = CreateInspectable(seqIndex + ".", 0, 0,
+                        new InspectableFieldLayout(layout), property);
+                }
 
                 return field.GetTitleLayout();
             }
@@ -263,16 +279,8 @@ namespace BansheeEditor
             {
                 if (field.IsModified())
                 {
-                    // If rebuild GUI is set to true, we will just rebuild the entire inspectable field, so no need to 
-                    // call Update on the existing one.
-                    if (!field.ShouldRebuildOnModify())
-                    {
-                        rebuildGUI = false;
-                        return field.Refresh(0);
-                    }
-
-                    rebuildGUI = true;
-                    return true;
+                    rebuildGUI = field.ShouldRebuildOnModify();
+                    return field.Refresh(0);
                 }
 
                 rebuildGUI = false;

+ 25 - 17
MBansheeEditor/Inspector/InspectableList.cs

@@ -55,7 +55,13 @@ namespace BansheeEditor
         /// <inheritdoc/>
         public override bool Refresh(int layoutIndex)
         {
-            bool anythingModified = IsModified();
+            bool anythingModified = false;
+
+            if (IsModified())
+            {
+                Update(layoutIndex);
+                anythingModified = true;
+            }
 
             anythingModified |= listGUIField.Refresh();
             return anythingModified;
@@ -98,6 +104,15 @@ namespace BansheeEditor
         {
             private SerializableProperty property;
 
+            /// <summary>
+            /// Constructs an inspectable list GUI.
+            /// </summary>
+            /// <param name="property">Serializable property referencing a list.</param>
+            private InspectableListGUI(SerializableProperty property)
+            {
+                this.property = property;
+            }
+            
             /// <summary>
             /// Creates a new inspectable GUI list.
             /// </summary>
@@ -107,7 +122,7 @@ namespace BansheeEditor
             /// <returns>Newly created inspectable GUI list object.</returns>
             public static InspectableListGUI Create(LocString title, SerializableProperty property, GUILayout layout)
             {
-                InspectableListGUI newArrayField = new InspectableListGUI();
+                InspectableListGUI newArrayField = new InspectableListGUI(property);
 
                 object propertyValue = property.GetValue<object>();
                 if (propertyValue != null)
@@ -118,8 +133,6 @@ namespace BansheeEditor
                 else
                     newArrayField.Construct<InspectableListGUIRow>(title, true, 0, layout);
 
-                newArrayField.property = property;
-
                 return newArrayField;
             }
 
@@ -223,10 +236,13 @@ namespace BansheeEditor
             /// <inheritdoc/>
             protected override GUILayoutX CreateGUI(GUILayoutY layout)
             {
-                SerializableProperty property = GetValue<SerializableProperty>();
+                if (field == null)
+                {
+                    SerializableProperty property = GetValue<SerializableProperty>();
 
-                field = CreateInspectable(seqIndex + ".", 0, 0,
-                    new InspectableFieldLayout(layout), property);
+                    field = CreateInspectable(seqIndex + ".", 0, 0,
+                        new InspectableFieldLayout(layout), property);
+                }
 
                 return field.GetTitleLayout();
             }
@@ -236,16 +252,8 @@ namespace BansheeEditor
             {
                 if (field.IsModified())
                 {
-                    // If rebuild GUI is set to true, we will just rebuild the entire inspectable field, so no need to 
-                    // call Update on the existing one.
-                    if (!field.ShouldRebuildOnModify())
-                    {
-                        rebuildGUI = false;
-                        return field.Refresh(0);
-                    }
-
-                    rebuildGUI = true;
-                    return true;
+                    rebuildGUI = field.ShouldRebuildOnModify();
+                    return field.Refresh(0);
                 }
 
                 rebuildGUI = false;