From aa23e882faf6fcc629a2975134684c2d77d9187a Mon Sep 17 00:00:00 2001 From: chrisgregan Date: Fri, 26 Sep 2014 15:35:41 +0100 Subject: [PATCH] Hide script field for commands in inspector. This fixes an issue where the user could change the type of script being used for a command which would trigger a bunch of null exception errors (because the commandList might now contain a null entry). --- .../FungusScript/Editor/CommandEditor.cs | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/Assets/Fungus/FungusScript/Editor/CommandEditor.cs b/Assets/Fungus/FungusScript/Editor/CommandEditor.cs index c5a862f9..d8831628 100644 --- a/Assets/Fungus/FungusScript/Editor/CommandEditor.cs +++ b/Assets/Fungus/FungusScript/Editor/CommandEditor.cs @@ -107,7 +107,27 @@ namespace Fungus public virtual void DrawCommandGUI() { - DrawDefaultInspector(); + // Code below was copied from here + // http://answers.unity3d.com/questions/550829/how-to-add-a-script-field-in-custom-inspector.html + + // Users should not be able to change the MonoScript for the command using the usual Script field. + // Doing so could cause sequence.commandList to contain null entries. + // To avoid this we manually display all properties, except for m_Script. + serializedObject.Update(); + SerializedProperty iterator = serializedObject.GetIterator(); + bool enterChildren = true; + while (iterator.NextVisible(enterChildren)) + { + enterChildren = false; + + if (iterator.name == "m_Script") + { + continue; + } + + EditorGUILayout.PropertyField(iterator, true, new GUILayoutOption[0]); + } + serializedObject.ApplyModifiedProperties(); } static public void ObjectField(SerializedProperty property, GUIContent label, GUIContent nullLabel, List objectList) where T : MonoBehaviour