From 2aed71ae4720e81292d7b626a0ad1cf33d9b819f Mon Sep 17 00:00:00 2001 From: chrisgregan Date: Fri, 8 Aug 2014 18:21:50 +0100 Subject: [PATCH] Removed ability to change variable type --- .../Editor/FungusScript/FungusScriptEditor.cs | 51 +++++++++++-------- .../FungusScript/FungusVariableEditor.cs | 21 +++++++- 2 files changed, 49 insertions(+), 23 deletions(-) diff --git a/Assets/Fungus/Editor/FungusScript/FungusScriptEditor.cs b/Assets/Fungus/Editor/FungusScript/FungusScriptEditor.cs index a0b68f61..560bdf8b 100644 --- a/Assets/Fungus/Editor/FungusScript/FungusScriptEditor.cs +++ b/Assets/Fungus/Editor/FungusScript/FungusScriptEditor.cs @@ -43,18 +43,6 @@ namespace Fungus.Script Selection.activeGameObject = go; } - if (GUILayout.Button("Add Variable")) - { - GenericMenu menu = new GenericMenu (); - - menu.AddItem(new GUIContent ("Boolean"), false, AddBooleanVariable, t); - menu.AddItem (new GUIContent ("Integer"), false, AddIntegerVariable, t); - menu.AddItem (new GUIContent ("Float"), false, AddFloatVariable, t); - menu.AddItem (new GUIContent ("String"), false, AddStringVariable, t); - - menu.ShowAsContext (); - } - GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); @@ -75,7 +63,22 @@ namespace Fungus.Script } ReorderableListGUI.Title("Variables"); - ReorderableListGUI.ListField(variablesProperty); + ReorderableListGUI.ListField(variablesProperty, ReorderableListFlags.DisableContextMenu | ReorderableListFlags.HideAddButton ); + + GUILayout.BeginHorizontal(); + GUILayout.FlexibleSpace(); + if (GUILayout.Button("Add Variable")) + { + GenericMenu menu = new GenericMenu (); + + menu.AddItem(new GUIContent ("Boolean"), false, AddBooleanVariable, t); + menu.AddItem (new GUIContent ("Integer"), false, AddIntegerVariable, t); + menu.AddItem (new GUIContent ("Float"), false, AddFloatVariable, t); + menu.AddItem (new GUIContent ("String"), false, AddStringVariable, t); + + menu.ShowAsContext (); + } + GUILayout.EndHorizontal(); serializedObject.ApplyModifiedProperties(); } @@ -87,9 +90,11 @@ namespace Fungus.Script { return; } - - FungusVariable variable = fungusScript.gameObject.AddComponent(); + + Variable variable = new Variable(); variable.key = MakeUniqueKey(fungusScript); + variable.type = VariableType.Boolean; + fungusScript.variables.Add(variable); } void AddIntegerVariable(object obj) @@ -100,8 +105,10 @@ namespace Fungus.Script return; } - FungusVariable variable = fungusScript.gameObject.AddComponent(); + Variable variable = new Variable(); variable.key = MakeUniqueKey(fungusScript); + variable.type = VariableType.Integer; + fungusScript.variables.Add(variable); } void AddFloatVariable(object obj) @@ -112,8 +119,10 @@ namespace Fungus.Script return; } - FungusVariable variable = fungusScript.gameObject.AddComponent(); + Variable variable = new Variable(); variable.key = MakeUniqueKey(fungusScript); + variable.type = VariableType.Float; + fungusScript.variables.Add(variable); } void AddStringVariable(object obj) @@ -124,21 +133,21 @@ namespace Fungus.Script return; } - FungusVariable variable = fungusScript.gameObject.AddComponent(); + Variable variable = new Variable(); variable.key = MakeUniqueKey(fungusScript); + variable.type = VariableType.String; + fungusScript.variables.Add(variable); } string MakeUniqueKey(FungusScript fungusScript) { - FungusVariable[] variables = fungusScript.GetComponents(); - int index = 0; while (true) { string key = "Var" + index; bool found = false; - foreach(FungusVariable variable in variables) + foreach(Variable variable in fungusScript.variables) { if (variable.key == key) { diff --git a/Assets/Fungus/Editor/FungusScript/FungusVariableEditor.cs b/Assets/Fungus/Editor/FungusScript/FungusVariableEditor.cs index ee1c3b57..0c799d27 100644 --- a/Assets/Fungus/Editor/FungusScript/FungusVariableEditor.cs +++ b/Assets/Fungus/Editor/FungusScript/FungusVariableEditor.cs @@ -39,7 +39,25 @@ namespace Fungus.Script scopeRect.width = width3; string keyValue = EditorGUI.TextField(keyRect, label, keyProp.stringValue); - int typeValue = (int)(VariableType)EditorGUI.EnumPopup(typeRect, (VariableType)typeProp.enumValueIndex); + + string typeLabel = ""; + switch ((VariableType)typeProp.enumValueIndex) + { + case VariableType.Boolean: + typeLabel = "Boolean"; + break; + case VariableType.Integer: + typeLabel = "Integer"; + break; + case VariableType.Float: + typeLabel = "Float"; + break; + case VariableType.String: + typeLabel = "String"; + break; + } + GUI.Label(typeRect, typeLabel); + int scopeValue = (int)(VariableScope)EditorGUI.EnumPopup(scopeRect, (VariableScope)scopeProp.enumValueIndex); if (EditorGUI.EndChangeCheck ()) @@ -49,7 +67,6 @@ namespace Fungus.Script keyValue = new string(arr); keyProp.stringValue = keyValue; - typeProp.enumValueIndex = typeValue; scopeProp.enumValueIndex = scopeValue; }