From 33397f004f4a52dcd2cb1670218ba0289616c7d1 Mon Sep 17 00:00:00 2001 From: chrisgregan Date: Wed, 10 Sep 2014 17:09:48 +0100 Subject: [PATCH] Converted FungusVariableListAdapter to use SerializedProperty --- Assets/Example/Scenes/Example.unity | Bin 128404 -> 128404 bytes .../Editor/FungusVariableListAdaptor.cs | 20 +++++++++--------- .../FungusScript/Editor/SequenceEditor.cs | 1 + 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/Assets/Example/Scenes/Example.unity b/Assets/Example/Scenes/Example.unity index 2f4d97401a9c36af371936aae8a6afcfd513e151..e29d0f584258c9ebd904e2c07ef5f16ca942640e 100644 GIT binary patch delta 60 zcmbR8ntjS^_J%Et2`^L+{9EnB00(=VflPZ4_ixMPND$2x;;Fze{h~Re@b(!m82|79 E07Q@x{{R30 delta 60 zcmbR8ntjS^_J%Et2`^MP{9EqC00(=VflPZ4_ixMPNH{(HqB*1R_8Bi2|L_0+T}czs diff --git a/Assets/Fungus/FungusScript/Editor/FungusVariableListAdaptor.cs b/Assets/Fungus/FungusScript/Editor/FungusVariableListAdaptor.cs index 0f18df02..e26a96e4 100644 --- a/Assets/Fungus/FungusScript/Editor/FungusVariableListAdaptor.cs +++ b/Assets/Fungus/FungusScript/Editor/FungusVariableListAdaptor.cs @@ -201,20 +201,20 @@ namespace Fungus.Script } else { - EditorGUI.BeginChangeCheck(); - key = EditorGUI.TextField(keyRect, variable.key); GUI.Label(valueRect, type); scope = (VariableScope)EditorGUI.EnumPopup(scopeRect, variable.scope); - if (EditorGUI.EndChangeCheck ()) - { - Undo.RecordObject(variable, "Set Variable"); - - // Modify the key if it clashes with an existing variable key - variable.key = fungusScript.GetUniqueVariableKey(key, variable); - variable.scope = scope; - } + // To access properties in a monobehavior, you have new a SerializedObject + // http://answers.unity3d.com/questions/629803/findrelativeproperty-never-worked-for-me-how-does.html + SerializedObject variableObject = new SerializedObject(this[index].objectReferenceValue); + SerializedProperty keyProp = variableObject.FindProperty("key"); + SerializedProperty scopeProp = variableObject.FindProperty("scope"); + + variableObject.Update(); + keyProp.stringValue = fungusScript.GetUniqueVariableKey(key, variable); + scopeProp.enumValueIndex = (int)scope; + variableObject.ApplyModifiedProperties(); } GUI.backgroundColor = Color.white; diff --git a/Assets/Fungus/FungusScript/Editor/SequenceEditor.cs b/Assets/Fungus/FungusScript/Editor/SequenceEditor.cs index 428d8d22..4391f2df 100644 --- a/Assets/Fungus/FungusScript/Editor/SequenceEditor.cs +++ b/Assets/Fungus/FungusScript/Editor/SequenceEditor.cs @@ -76,6 +76,7 @@ namespace Fungus.Script GUILayout.Label("New Command"); GUILayout.FlexibleSpace(); + // We should probably use SerializedProperty for the category & command index but there's no real benefit to doing so int selectedCategoryIndex = EditorGUILayout.Popup(fungusScript.selectedCommandCategoryIndex, categories.ToArray());