Browse Source

Added buttons to create and delete variables.

master
chrisgregan 11 years ago
parent
commit
f2be7f774b
  1. 86
      Assets/Fungus/Editor/FungusScript/FungusScriptEditor.cs
  2. 9
      Assets/Fungus/Editor/FungusScript/FungusVariableEditor.cs
  3. BIN
      Assets/Shuttle/ShuttleGame.unity

86
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<BooleanVariable>();
variable.key = MakeUniqueKey(fungusScript);
}
void AddIntegerVariable(object obj)
{
FungusScript fungusScript = obj as FungusScript;
if (fungusScript == null)
{
return;
}
FungusVariable variable = fungusScript.gameObject.AddComponent<IntegerVariable>();
variable.key = MakeUniqueKey(fungusScript);
}
void AddFloatVariable(object obj)
{
FungusScript fungusScript = obj as FungusScript;
if (fungusScript == null)
{
return;
}
FungusVariable variable = fungusScript.gameObject.AddComponent<FloatVariable>();
variable.key = MakeUniqueKey(fungusScript);
}
void AddStringVariable(object obj)
{
FungusScript fungusScript = obj as FungusScript;
if (fungusScript == null)
{
return;
}
FungusVariable variable = fungusScript.gameObject.AddComponent<StringVariable>();
variable.key = MakeUniqueKey(fungusScript);
}
string MakeUniqueKey(FungusScript fungusScript)
{
FungusVariable[] variables = fungusScript.GetComponents<FungusVariable>();
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;
}
}
}
}
}

9
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<FungusVariable, bool> filter = null)

BIN
Assets/Shuttle/ShuttleGame.unity

Binary file not shown.
Loading…
Cancel
Save