diff --git a/Assets/Fungus/Editor/FungusScript/FungusScriptEditor.cs b/Assets/Fungus/Editor/FungusScript/FungusScriptEditor.cs index 28b49ba4..1e6ca0fe 100644 --- a/Assets/Fungus/Editor/FungusScript/FungusScriptEditor.cs +++ b/Assets/Fungus/Editor/FungusScript/FungusScriptEditor.cs @@ -92,6 +92,18 @@ namespace Fungus.Script Undo.RegisterCreatedObjectUndo(go, "Sequence"); 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(); @@ -117,6 +129,80 @@ namespace Fungus.Script //serializedObject.ApplyModifiedProperties(); } + + void AddBooleanVariable(object obj) + { + FungusScript fungusScript = obj as FungusScript; + if (fungusScript == null) + { + return; + } + + FungusVariable variable = fungusScript.gameObject.AddComponent(); + variable.key = MakeUniqueKey(fungusScript); + } + + void AddIntegerVariable(object obj) + { + FungusScript fungusScript = obj as FungusScript; + if (fungusScript == null) + { + return; + } + + FungusVariable variable = fungusScript.gameObject.AddComponent(); + variable.key = MakeUniqueKey(fungusScript); + } + + void AddFloatVariable(object obj) + { + FungusScript fungusScript = obj as FungusScript; + if (fungusScript == null) + { + return; + } + + FungusVariable variable = fungusScript.gameObject.AddComponent(); + variable.key = MakeUniqueKey(fungusScript); + } + + void AddStringVariable(object obj) + { + FungusScript fungusScript = obj as FungusScript; + if (fungusScript == null) + { + return; + } + + FungusVariable variable = fungusScript.gameObject.AddComponent(); + variable.key = MakeUniqueKey(fungusScript); + } + + 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) + { + if (variable.key == key) + { + found = true; + index++; + } + } + + if (!found) + { + return key; + } + } + } } } \ No newline at end of file diff --git a/Assets/Fungus/Editor/FungusScript/FungusVariableEditor.cs b/Assets/Fungus/Editor/FungusScript/FungusVariableEditor.cs index 2ba74e49..d200e8f3 100644 --- a/Assets/Fungus/Editor/FungusScript/FungusVariableEditor.cs +++ b/Assets/Fungus/Editor/FungusScript/FungusVariableEditor.cs @@ -26,6 +26,15 @@ namespace Fungus.Script t.key = key; t.scope = scope; } + + GUILayout.BeginHorizontal(); + GUILayout.FlexibleSpace(); + if (GUILayout.Button("Delete Variable")) + { + Undo.RecordObject(t, "Delete Variable"); + DestroyImmediate(t); + } + GUILayout.EndHorizontal(); } static public FungusVariable VariableField(GUIContent label, FungusScript fungusScript, FungusVariable variable, Func filter = null) diff --git a/Assets/Shuttle/ShuttleGame.unity b/Assets/Shuttle/ShuttleGame.unity index e6f4df54..092d911a 100644 Binary files a/Assets/Shuttle/ShuttleGame.unity and b/Assets/Shuttle/ShuttleGame.unity differ