From f2be7f774b8a069acda052d1e04f2f9beda02c60 Mon Sep 17 00:00:00 2001 From: chrisgregan Date: Fri, 8 Aug 2014 11:56:03 +0100 Subject: [PATCH] Added buttons to create and delete variables. --- .../Editor/FungusScript/FungusScriptEditor.cs | 86 ++++++++++++++++++ .../FungusScript/FungusVariableEditor.cs | 9 ++ Assets/Shuttle/ShuttleGame.unity | Bin 79052 -> 79180 bytes 3 files changed, 95 insertions(+) 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 e6f4df54d432f3bbeae3b6da0dfd1ef891540108..092d911a9260be4fd420208415cf835b13cec9e2 100644 GIT binary patch delta 2173 zcmZwIVN6q36bJBgS%Knk7F(blAT1P!OtdHpCNir-1Dl2-%&}!NRIP|26et_pSRjjT zXqJh)lZT*5_hn(r5@mI%U)fMJLJkL?9$9I4`FCO3dQhB4Vm<}~HHF(^O2iy&99%3lG4okem zcPbZeMD>k6u{?F2mT005n8(>BOWe_hCN~PMG-s@C^|jPD)=~6hF^}&sTX^PxAts;r zr!Qx+4ZL!|#x@3SnRmU-QUkW6*xaMMYzyT!vz@h4XQw_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