From 972e69cda4cb180f8e16e5941d7eaa13a2b82f5f Mon Sep 17 00:00:00 2001 From: chrisgregan Date: Tue, 4 Aug 2015 11:57:47 +0100 Subject: [PATCH] Use reorderable list for all lists & arrays in command inspector Added overridable IsPropertyVisible() method to hide specific properties as needed. --- .../Fungus/Flowchart/Editor/CommandEditor.cs | 18 +++++++++++++++++- Assets/Fungus/Flowchart/Scripts/Command.cs | 9 +++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/Assets/Fungus/Flowchart/Editor/CommandEditor.cs b/Assets/Fungus/Flowchart/Editor/CommandEditor.cs index 7a469c81..2d5ef045 100644 --- a/Assets/Fungus/Flowchart/Editor/CommandEditor.cs +++ b/Assets/Fungus/Flowchart/Editor/CommandEditor.cs @@ -3,6 +3,7 @@ using UnityEditorInternal; using UnityEngine; using System.Collections; using System.Collections.Generic; +using Rotorz.ReorderableList; namespace Fungus { @@ -113,6 +114,8 @@ namespace Fungus public virtual void DrawCommandGUI() { + Command t = target as Command; + // Code below was copied from here // http://answers.unity3d.com/questions/550829/how-to-add-a-script-field-in-custom-inspector.html @@ -131,7 +134,20 @@ namespace Fungus continue; } - EditorGUILayout.PropertyField(iterator, true, new GUILayoutOption[0]); + if (!t.IsPropertyVisible(iterator.name)) + { + continue; + } + + if (iterator.isArray) + { + ReorderableListGUI.Title(new GUIContent(iterator.displayName, iterator.tooltip)); + ReorderableListGUI.ListField(iterator); + } + else + { + EditorGUILayout.PropertyField(iterator, true, new GUILayoutOption[0]); + } } serializedObject.ApplyModifiedProperties(); diff --git a/Assets/Fungus/Flowchart/Scripts/Command.cs b/Assets/Fungus/Flowchart/Scripts/Command.cs index ce7b9171..9f4c126c 100644 --- a/Assets/Fungus/Flowchart/Scripts/Command.cs +++ b/Assets/Fungus/Flowchart/Scripts/Command.cs @@ -166,6 +166,15 @@ namespace Fungus { return Color.white; } + + /** + * Returns true if the specified property should be displayed in the inspector. + * This is useful for hiding certain properties based on the value of another property. + */ + public virtual bool IsPropertyVisible(string propertyName) + { + return true; + } } } \ No newline at end of file