From b547553c208a789b42a49fe4b371d8f50b8f4687 Mon Sep 17 00:00:00 2001 From: chrisgregan Date: Wed, 10 Sep 2014 15:53:54 +0100 Subject: [PATCH] Converted SetVariable and If to use serialized property --- Assets/Example/Scenes/Example.unity | Bin 128100 -> 128204 bytes Assets/Fungus/Dialog/Commands/Say.cs | 4 +- Assets/Fungus/Dialog/Editor/SayEditor.cs | 1 - .../Editor/FungusVariableEditor.cs | 9 ++- Assets/Fungus/FungusScript/Editor/IfEditor.cs | 69 +++++++++-------- .../FungusScript/Editor/SetVariableEditor.cs | 72 ++++++++++-------- 6 files changed, 90 insertions(+), 65 deletions(-) diff --git a/Assets/Example/Scenes/Example.unity b/Assets/Example/Scenes/Example.unity index 4b5860411a85daff05b1424c4fb01cf8762123f0..f564160db9941f4299691826383255d2b1fb9a01 100644 GIT binary patch delta 1264 zcmY+DYe-a45XaBth6++vLKa3A8!4&mhyAdjkv*Vy7+4fsNDI-RXp_Q6>TYSRrSxE> ziHhh$P!PClNw+{_Ka`kV$co%Pq`N*a1p^=36U+Yh-cxQDhI8h3X8tpC4tHoIRvV2? z6jU4(6w!nb@z{^IB(7@ry0c@wPuu5tuVtU{X16c#W^M|3$5+HY>Ux%NnU<=-U371e z>l9K*noqGF8>tbZ4!%X2AI#|z!VSNFW@e@oYYW&o*jDVrl05`-ASgGAiNOA{aAMhn(~B{%$^d=BghSRQhE zrQmt6xJDsPf{jY%0ds>XU{jK1sIL!`KPK_#&6c8$zU>PhEW5ofXXBv86~%N=9Vn(l z%Xz1V$}JrWgKIh9A%(5=bTWQu!?*d65rX?K&>Ho5J*Caz$VIYS^b-yorzF+UK+`KZ zr)Wk{0T-^ zOBeK!k~9~?>^+v1m1T@2gfXyw!uAlQnF@y67NVnOo)RJ(=ZDd9BuoXfTHMGu=3qcq|hA3ALCe?pbWN6l9e+i xaC^!G<(ijio5CCA;R>$}Q6ejql%jhHdTbj4Qd)mF1$cJs2$7Lw|hm!JuG)!3ed9SJ0TTNYmW>Z`q&4 z4UUix^;8kHNe}l$!FKLy**B>`2_L8Xxt@BIBw>C>QDdx~v2L7=!UABDhcPeC z)62`t=dlihCBVwDj|s-cDlb|PbQi^D4JrFtcjscLgRzr{OZWH&X6{_+;n5nsWRETd z0Bd!DufX!V7;96T2zw1S2tY0ENt~S zS`&ckO%_GL8_RFnEIt2=xd}E1rWfM_%kO2ZAGyCo?k%vpV0tlaW0A{aV9ybk7IPV_ zzYk(C#T7N}fHA<^U<;z42do(#8o+)C<^@ZDRe((i)&XX{!q^blPr*9DB4Db(s9;@S zRagJjJEgv7H(&@*pWFlH8er@M{F5TN7ijp~!7RKYK!d4ZO-ejKMZDZk zdllO-4HoJ=AKub!E=g3V_}-D-pn5WSe4Ik6@**Dl2)D-EVR9&uFvX3!?2!p7Dp`dIo@y*9DdE);<#Jz?Ds<&4rpWv+!KfAaFhvdA zJ4JiBJC?qa=E$C=DqXNPl;AW*s0EjP`Y$;63DbfUi(>msRs$LMg&8X54`!&Gha$9! zCuc}0I-KD<%Gk&;h}6EN?)RtFjk9G^QrB}>dGHGcAth)clXmm#cu4L_;ue-hyt^i1 gBuR(4Gl^FyOG0+lcUsU5#Xb+O@jKpfZk{Io0%x|nGXMYp diff --git a/Assets/Fungus/Dialog/Commands/Say.cs b/Assets/Fungus/Dialog/Commands/Say.cs index 868c55bb..d52588d6 100644 --- a/Assets/Fungus/Dialog/Commands/Say.cs +++ b/Assets/Fungus/Dialog/Commands/Say.cs @@ -10,8 +10,10 @@ namespace Fungus.Script "Writes a line of story text to the dialog. A list of options can be specified for the player to choose from. Use a non-zero timeout to give the player a limited time to choose.")] public class Say : FungusCommand { - public Character character; + [TextArea(5,10)] public string storyText; + + public Character character; public AudioClip voiceOverClip; public bool showOnce; int executionCount; diff --git a/Assets/Fungus/Dialog/Editor/SayEditor.cs b/Assets/Fungus/Dialog/Editor/SayEditor.cs index 70587af9..29577191 100644 --- a/Assets/Fungus/Dialog/Editor/SayEditor.cs +++ b/Assets/Fungus/Dialog/Editor/SayEditor.cs @@ -48,7 +48,6 @@ namespace Fungus.Script serializedObject.Update(); EditorGUILayout.BeginHorizontal(); - EditorGUILayout.PrefixLabel(new GUIContent("Say Text", "Text to display in dialog")); GUILayout.FlexibleSpace(); if (GUILayout.Button(new GUIContent("Tag Help", "Show help info for tags"), new GUIStyle(EditorStyles.miniButton))) { diff --git a/Assets/Fungus/FungusScript/Editor/FungusVariableEditor.cs b/Assets/Fungus/FungusScript/Editor/FungusVariableEditor.cs index d1194efb..94a6c7ed 100644 --- a/Assets/Fungus/FungusScript/Editor/FungusVariableEditor.cs +++ b/Assets/Fungus/FungusScript/Editor/FungusVariableEditor.cs @@ -17,7 +17,7 @@ namespace Fungus.Script t.hideFlags = HideFlags.HideInInspector; } - static public FungusVariable VariableField(GUIContent label, FungusScript fungusScript, FungusVariable variable, Func filter = null) + static public void VariableField(SerializedProperty property, GUIContent label, FungusScript fungusScript, Func filter = null) { List variableKeys = new List(); List variableObjects = new List(); @@ -28,6 +28,9 @@ namespace Fungus.Script List variables = fungusScript.variables; int index = 0; int selectedIndex = 0; + + FungusVariable selectedVariable = property.objectReferenceValue as FungusVariable; + foreach (FungusVariable v in variables) { if (filter != null) @@ -43,7 +46,7 @@ namespace Fungus.Script index++; - if (v == variable) + if (v == selectedVariable) { selectedIndex = index; } @@ -51,7 +54,7 @@ namespace Fungus.Script selectedIndex = EditorGUILayout.Popup(label.text, selectedIndex, variableKeys.ToArray()); - return variableObjects[selectedIndex]; + property.objectReferenceValue = variableObjects[selectedIndex]; } } diff --git a/Assets/Fungus/FungusScript/Editor/IfEditor.cs b/Assets/Fungus/FungusScript/Editor/IfEditor.cs index b4f56a5b..d65630ec 100644 --- a/Assets/Fungus/FungusScript/Editor/IfEditor.cs +++ b/Assets/Fungus/FungusScript/Editor/IfEditor.cs @@ -9,6 +9,23 @@ namespace Fungus.Script [CustomEditor (typeof(If))] public class IfEditor : FungusCommandEditor { + SerializedProperty variableProp; + SerializedProperty compareOperatorProp; + SerializedProperty booleanValueProp; + SerializedProperty integerValueProp; + SerializedProperty floatValueProp; + SerializedProperty stringValueProp; + + void OnEnable() + { + variableProp = serializedObject.FindProperty("variable"); + compareOperatorProp = serializedObject.FindProperty("compareOperator"); + booleanValueProp = serializedObject.FindProperty("booleanValue"); + integerValueProp = serializedObject.FindProperty("integerValue"); + floatValueProp = serializedObject.FindProperty("floatValue"); + stringValueProp = serializedObject.FindProperty("stringValue"); + } + public override void DrawCommandGUI() { serializedObject.Update(); @@ -21,27 +38,25 @@ namespace Fungus.Script return; } - FungusVariable fungusVariable = FungusVariableEditor.VariableField(new GUIContent("Variable", "Variable to use in operation"), - t.GetFungusScript(), - t.variable, - null); - - if (fungusVariable != t.variable) - { - Undo.RecordObject(t, "Select Variable"); - t.variable = fungusVariable; - } + FungusVariableEditor.VariableField(variableProp, + new GUIContent("Variable", "Variable to use in operation"), + t.GetFungusScript(), + null); - if (t.variable == null) + if (variableProp.objectReferenceValue == null) { + serializedObject.ApplyModifiedProperties(); return; } + FungusVariable selectedVariable = variableProp.objectReferenceValue as FungusVariable; + System.Type variableType = selectedVariable.GetType(); + List operatorList = new List(); operatorList.Add(new GUIContent("==")); operatorList.Add(new GUIContent("!=")); - if (t.variable.GetType() == typeof(IntegerVariable) || - t.variable.GetType() == typeof(FloatVariable)) + if (variableType == typeof(IntegerVariable) || + variableType == typeof(FloatVariable)) { operatorList.Add(new GUIContent("<")); operatorList.Add(new GUIContent(">")); @@ -49,31 +64,25 @@ namespace Fungus.Script operatorList.Add(new GUIContent(">=")); } - CompareOperator compareOperator = (CompareOperator)EditorGUILayout.Popup(new GUIContent("Compare", - "The comparison operator to use when comparing values"), - (int)t.compareOperator, - operatorList.ToArray()); - if (compareOperator != t.compareOperator) - { - Undo.RecordObject(t, "Select Compare Operator"); - t.compareOperator = compareOperator; - } + compareOperatorProp.enumValueIndex = EditorGUILayout.Popup(new GUIContent("Compare", "The comparison operator to use when comparing values"), + compareOperatorProp.enumValueIndex, + operatorList.ToArray()); - if (t.variable.GetType() == typeof(BooleanVariable)) + if (variableType == typeof(BooleanVariable)) { - EditorGUILayout.PropertyField(serializedObject.FindProperty("booleanValue")); + EditorGUILayout.PropertyField(booleanValueProp); } - else if (t.variable.GetType() == typeof(IntegerVariable)) + else if (variableType == typeof(IntegerVariable)) { - EditorGUILayout.PropertyField(serializedObject.FindProperty("integerValue")); + EditorGUILayout.PropertyField(integerValueProp); } - else if (t.variable.GetType() == typeof(FloatVariable)) + else if (variableType == typeof(FloatVariable)) { - EditorGUILayout.PropertyField(serializedObject.FindProperty("floatValue")); + EditorGUILayout.PropertyField(floatValueProp); } - else if (t.variable.GetType() == typeof(StringVariable)) + else if (variableType == typeof(StringVariable)) { - EditorGUILayout.PropertyField(serializedObject.FindProperty("stringValue")); + EditorGUILayout.PropertyField(stringValueProp); } serializedObject.ApplyModifiedProperties(); diff --git a/Assets/Fungus/FungusScript/Editor/SetVariableEditor.cs b/Assets/Fungus/FungusScript/Editor/SetVariableEditor.cs index 268d86c8..23d0835d 100644 --- a/Assets/Fungus/FungusScript/Editor/SetVariableEditor.cs +++ b/Assets/Fungus/FungusScript/Editor/SetVariableEditor.cs @@ -9,6 +9,23 @@ namespace Fungus.Script [CustomEditor (typeof(SetVariable))] public class SetVariableEditor : FungusCommandEditor { + SerializedProperty variableProp; + SerializedProperty setOperatorProp; + SerializedProperty booleanDataProp; + SerializedProperty integerDataProp; + SerializedProperty floatDataProp; + SerializedProperty stringDataProp; + + void OnEnable() + { + variableProp = serializedObject.FindProperty("variable"); + setOperatorProp = serializedObject.FindProperty("setOperator"); + booleanDataProp = serializedObject.FindProperty("booleanData"); + integerDataProp = serializedObject.FindProperty("integerData"); + floatDataProp = serializedObject.FindProperty("floatData"); + stringDataProp = serializedObject.FindProperty("stringData"); + } + public override void DrawCommandGUI() { serializedObject.Update(); @@ -21,29 +38,28 @@ namespace Fungus.Script return; } - FungusVariable variable = FungusVariableEditor.VariableField(new GUIContent("Variable", "Variable to set"), - fungusScript, - t.variable); + FungusVariableEditor.VariableField(variableProp, + new GUIContent("Variable", "Variable to set"), + fungusScript); - if (variable != t.variable) - { - Undo.RecordObject(t, "Set Variable Key"); - t.variable = variable; - } - if (t.variable == null) + if (variableProp.objectReferenceValue == null) { + serializedObject.ApplyModifiedProperties(); return; } - + + FungusVariable selectedVariable = variableProp.objectReferenceValue as FungusVariable; + System.Type variableType = selectedVariable.GetType(); + List operatorsList = new List(); operatorsList.Add(new GUIContent("=")); - if (variable.GetType() == typeof(BooleanVariable)) + if (variableType == typeof(BooleanVariable)) { operatorsList.Add(new GUIContent("!")); } - else if (variable.GetType() == typeof(IntegerVariable) || - variable.GetType() == typeof(FloatVariable)) + else if (variableType == typeof(IntegerVariable) || + variableType == typeof(FloatVariable)) { operatorsList.Add(new GUIContent("+=")); operatorsList.Add(new GUIContent("-=")); @@ -78,8 +94,8 @@ namespace Fungus.Script selectedIndex = EditorGUILayout.Popup(new GUIContent("Operator", "Arithmetic operator to use"), selectedIndex, operatorsList.ToArray()); SetVariable.SetOperator setOperator = SetVariable.SetOperator.Assign; - if (variable.GetType() == typeof(BooleanVariable) || - variable.GetType() == typeof(StringVariable)) + if (variableType == typeof(BooleanVariable) || + variableType == typeof(StringVariable)) { switch (selectedIndex) { @@ -92,8 +108,8 @@ namespace Fungus.Script break; } } - else if (variable.GetType() == typeof(IntegerVariable) || - variable.GetType() == typeof(FloatVariable)) + else if (variableType == typeof(IntegerVariable) || + variableType == typeof(FloatVariable)) { switch (selectedIndex) { @@ -116,27 +132,23 @@ namespace Fungus.Script } } - if (setOperator != t.setOperator) - { - Undo.RecordObject(t, "Set Operator"); - t.setOperator = setOperator; - } + setOperatorProp.enumValueIndex = (int)setOperator; - if (variable.GetType() == typeof(BooleanVariable)) + if (variableType == typeof(BooleanVariable)) { - EditorGUILayout.PropertyField(serializedObject.FindProperty("booleanData")); + EditorGUILayout.PropertyField(booleanDataProp); } - else if (variable.GetType() == typeof(IntegerVariable)) + else if (variableType == typeof(IntegerVariable)) { - EditorGUILayout.PropertyField(serializedObject.FindProperty("integerData")); + EditorGUILayout.PropertyField(integerDataProp); } - else if (variable.GetType() == typeof(FloatVariable)) + else if (variableType == typeof(FloatVariable)) { - EditorGUILayout.PropertyField(serializedObject.FindProperty("floatData")); + EditorGUILayout.PropertyField(floatDataProp); } - else if (variable.GetType() == typeof(StringVariable)) + else if (variableType == typeof(StringVariable)) { - EditorGUILayout.PropertyField(serializedObject.FindProperty("stringData")); + EditorGUILayout.PropertyField(stringDataProp); } serializedObject.ApplyModifiedProperties();