From 2279376b2714b5e194fdac561c67e36722ceef4d Mon Sep 17 00:00:00 2001 From: chrisgregan Date: Wed, 10 Sep 2014 14:35:04 +0100 Subject: [PATCH] Converted SequenceField to use SerializedProperty --- Assets/Example/Scenes/Example.unity | Bin 128084 -> 128084 bytes .../Fungus/Dialog/Editor/AddOptionEditor.cs | 34 ++++++----- .../Fungus/FungusScript/Editor/CallEditor.cs | 24 +++++--- .../FungusScript/Editor/FungusScriptEditor.cs | 55 +++++++++--------- .../FungusScript/Editor/SequenceEditor.cs | 16 ++--- 5 files changed, 71 insertions(+), 58 deletions(-) diff --git a/Assets/Example/Scenes/Example.unity b/Assets/Example/Scenes/Example.unity index b23bba79f38a154a2095e72736230cebc91e6311..e97975c33a3f9f25f180fbfe80d85ef732c05348 100644 GIT binary patch delta 62 zcmcceg8j-1_J%Et8P9b#{9EqC00a(90zi6?Gl&fWe_Jj`g6NdWyBQ!l6G(5L@|^Ji F4*;O#6jlHL delta 62 zcmcceg8j-1_J%Et8P9bN{9EnB00(=VVa&fRmm@*!x&t?AL39g{-ah3y;{hH3n9>xv diff --git a/Assets/Fungus/Dialog/Editor/AddOptionEditor.cs b/Assets/Fungus/Dialog/Editor/AddOptionEditor.cs index 8a17821a..536ff5b0 100644 --- a/Assets/Fungus/Dialog/Editor/AddOptionEditor.cs +++ b/Assets/Fungus/Dialog/Editor/AddOptionEditor.cs @@ -11,29 +11,35 @@ namespace Fungus.Script [CustomEditor (typeof(AddOption))] public class AddOptionEditor : FungusCommandEditor { + SerializedProperty optionTextProp; + SerializedProperty hideOnSelectedProp; + SerializedProperty targetSequenceProp; + + void OnEnable() + { + optionTextProp = serializedObject.FindProperty("optionText"); + hideOnSelectedProp = serializedObject.FindProperty("hideOnSelected"); + targetSequenceProp = serializedObject.FindProperty("targetSequence"); + } + public override void DrawCommandGUI() { + serializedObject.Update(); + AddOption t = target as AddOption; EditorGUI.BeginChangeCheck(); - string optionText = EditorGUILayout.TextField(new GUIContent("Option Text", "Text to display on the option button."), - t.optionText); + EditorGUILayout.PropertyField(optionTextProp, new GUIContent("Option Text", "Text to display on the option button.")); - Sequence targetSequence = SequenceEditor.SequenceField(new GUIContent("Target Sequence", "Sequence to execute when this option is selected by the player."), - new GUIContent(""), - t.GetFungusScript(), - t.targetSequence); + SequenceEditor.SequenceField(targetSequenceProp, + new GUIContent("Target Sequence", "Sequence to execute when this option is selected by the player."), + new GUIContent(""), + t.GetFungusScript()); - bool hideOnSelected = EditorGUILayout.Toggle(new GUIContent("Hide On Selected", "Hide this option forever once the player has selected it."), t.hideOnSelected); + EditorGUILayout.PropertyField(hideOnSelectedProp, new GUIContent("Hide On Selected", "Hide this option forever once the player has selected it.")); - if (EditorGUI.EndChangeCheck()) - { - Undo.RecordObject(t, "Set Add Option"); - t.optionText = optionText; - t.targetSequence = targetSequence; - t.hideOnSelected = hideOnSelected; - } + serializedObject.ApplyModifiedProperties(); } } diff --git a/Assets/Fungus/FungusScript/Editor/CallEditor.cs b/Assets/Fungus/FungusScript/Editor/CallEditor.cs index 99ed0495..8618894b 100644 --- a/Assets/Fungus/FungusScript/Editor/CallEditor.cs +++ b/Assets/Fungus/FungusScript/Editor/CallEditor.cs @@ -8,8 +8,17 @@ namespace Fungus.Script [CustomEditor (typeof(Call))] public class CallEditor : FungusCommandEditor { + SerializedProperty targetSequenceProp; + + void OnEnable() + { + targetSequenceProp = serializedObject.FindProperty("targetSequence"); + } + public override void DrawCommandGUI() { + serializedObject.Update(); + Call t = target as Call; FungusScript fungusScript = t.GetFungusScript(); @@ -18,15 +27,12 @@ namespace Fungus.Script return; } - Sequence targetSequence = SequenceEditor.SequenceField(new GUIContent("Target Sequence", "Sequence to call"), - new GUIContent(""), - fungusScript, - t.targetSequence); - if (targetSequence != t.targetSequence) - { - Undo.RecordObject(t, "Set Target Sequence"); - t.targetSequence = targetSequence; - } + SequenceEditor.SequenceField(targetSequenceProp, + new GUIContent("Target Sequence", "Sequence to call"), + new GUIContent(""), + fungusScript); + + serializedObject.ApplyModifiedProperties(); } } diff --git a/Assets/Fungus/FungusScript/Editor/FungusScriptEditor.cs b/Assets/Fungus/FungusScript/Editor/FungusScriptEditor.cs index f3405b09..3baa99e7 100644 --- a/Assets/Fungus/FungusScript/Editor/FungusScriptEditor.cs +++ b/Assets/Fungus/FungusScript/Editor/FungusScriptEditor.cs @@ -10,6 +10,21 @@ namespace Fungus.Script [CustomEditor (typeof(FungusScript))] public class FungusScriptEditor : Editor { + SerializedProperty stepTimeProp; + SerializedProperty startSequenceProp; + SerializedProperty startAutomaticallyProp; + SerializedProperty colorCommandsProp; + SerializedProperty variablesProp; + + void OnEnable() + { + stepTimeProp = serializedObject.FindProperty("stepTime"); + startSequenceProp = serializedObject.FindProperty("startSequence"); + startAutomaticallyProp = serializedObject.FindProperty("startAutomatically"); + colorCommandsProp = serializedObject.FindProperty("colorCommands"); + variablesProp = serializedObject.FindProperty("variables"); + } + public void OnInspectorUpdate() { Repaint(); @@ -17,12 +32,9 @@ namespace Fungus.Script public override void OnInspectorGUI() { - FungusScript t = target as FungusScript; + serializedObject.Update(); - if (t != null) - { - t.transform.hideFlags = HideFlags.None; - } + FungusScript t = target as FungusScript; if (Application.isPlaying) { @@ -38,12 +50,13 @@ namespace Fungus.Script EditorGUI.BeginChangeCheck(); - float stepTime = EditorGUILayout.FloatField(new GUIContent("Step Time", "Minimum time to execute each step"), t.stepTime); + EditorGUILayout.PropertyField(stepTimeProp, new GUIContent("Step Time", "Minimum time to execute each step")); + + SequenceEditor.SequenceField(startSequenceProp, + new GUIContent("Start Sequence", "Sequence to be executed when controller starts."), + new GUIContent(""), + t); - Sequence startSequence = SequenceEditor.SequenceField(new GUIContent("Start Sequence", "Sequence to be executed when controller starts."), - new GUIContent(""), - t, - t.startSequence); if (t.startSequence == null) { GUIStyle style = new GUIStyle(GUI.skin.label); @@ -51,18 +64,9 @@ namespace Fungus.Script EditorGUILayout.LabelField(new GUIContent("Error: Please select a Start Sequence"), style); } - bool startAutomatically = EditorGUILayout.Toggle(new GUIContent("Start Automatically", "Start this Fungus Script when the scene starts."), t.startAutomatically); + EditorGUILayout.PropertyField(startAutomaticallyProp, new GUIContent("Start Automatically", "Start this Fungus Script when the scene starts.")); - bool colorCommands = EditorGUILayout.Toggle(new GUIContent("Color Commands", "Display commands using colors in editor window."), t.colorCommands); - - if (EditorGUI.EndChangeCheck()) - { - Undo.RecordObject(t, "Set Fungus Script"); - t.stepTime = stepTime; - t.startSequence = startSequence; - t.startAutomatically = startAutomatically; - t.colorCommands = colorCommands; - } + EditorGUILayout.PropertyField(colorCommandsProp, new GUIContent("Color Commands", "Display commands using colors in editor window.")); EditorGUILayout.Separator(); @@ -86,18 +90,17 @@ namespace Fungus.Script EditorGUILayout.Separator(); DrawVariablesGUI(); + + serializedObject.ApplyModifiedProperties(); } public void DrawVariablesGUI() { - serializedObject.Update(); - FungusScript t = target as FungusScript; ReorderableListGUI.Title("Variables"); - SerializedProperty variablesProperty = serializedObject.FindProperty("variables"); - FungusVariableListAdaptor adaptor = new FungusVariableListAdaptor(variablesProperty, 0); + FungusVariableListAdaptor adaptor = new FungusVariableListAdaptor(variablesProp, 0); ReorderableListControl.DrawControlFromState(adaptor, null, ReorderableListFlags.DisableContextMenu | ReorderableListFlags.HideAddButton); GUILayout.BeginHorizontal(); @@ -115,8 +118,6 @@ namespace Fungus.Script menu.ShowAsContext (); } GUILayout.EndHorizontal(); - - serializedObject.ApplyModifiedProperties(); } void AddVariable(object obj) where T : FungusVariable diff --git a/Assets/Fungus/FungusScript/Editor/SequenceEditor.cs b/Assets/Fungus/FungusScript/Editor/SequenceEditor.cs index 24a95e1e..46eed8fd 100644 --- a/Assets/Fungus/FungusScript/Editor/SequenceEditor.cs +++ b/Assets/Fungus/FungusScript/Editor/SequenceEditor.cs @@ -168,15 +168,15 @@ namespace Fungus.Script } } - static public Sequence SequenceField(GUIContent label, GUIContent nullLabel, FungusScript fungusScript, Sequence sequence) + static public void SequenceField(SerializedProperty property, GUIContent label, GUIContent nullLabel, FungusScript fungusScript) { if (fungusScript == null) { - return null; + return; } - - Sequence result = sequence; - + + Sequence sequence = property.objectReferenceValue as Sequence; + // Build dictionary of child sequences List sequenceNames = new List(); @@ -196,14 +196,14 @@ namespace Fungus.Script selectedIndex = EditorGUILayout.Popup(label, selectedIndex, sequenceNames.ToArray()); if (selectedIndex == 0) { - result = null; // Option 'None' + sequence = null; // Option 'None' } else { - result = sequences[selectedIndex - 1]; + sequence = sequences[selectedIndex - 1]; } - return result; + property.objectReferenceValue = sequence; } static public Sequence SequenceField(Rect position, GUIContent nullLabel, FungusScript fungusScript, Sequence sequence)