Browse Source

Removed ability to change variable type

master
chrisgregan 11 years ago
parent
commit
2aed71ae47
  1. 51
      Assets/Fungus/Editor/FungusScript/FungusScriptEditor.cs
  2. 21
      Assets/Fungus/Editor/FungusScript/FungusVariableEditor.cs

51
Assets/Fungus/Editor/FungusScript/FungusScriptEditor.cs

@ -43,18 +43,6 @@ namespace Fungus.Script
Selection.activeGameObject = go; 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.FlexibleSpace();
GUILayout.EndHorizontal(); GUILayout.EndHorizontal();
@ -75,7 +63,22 @@ namespace Fungus.Script
} }
ReorderableListGUI.Title("Variables"); 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(); serializedObject.ApplyModifiedProperties();
} }
@ -87,9 +90,11 @@ namespace Fungus.Script
{ {
return; return;
} }
FungusVariable variable = fungusScript.gameObject.AddComponent<BooleanVariable>(); Variable variable = new Variable();
variable.key = MakeUniqueKey(fungusScript); variable.key = MakeUniqueKey(fungusScript);
variable.type = VariableType.Boolean;
fungusScript.variables.Add(variable);
} }
void AddIntegerVariable(object obj) void AddIntegerVariable(object obj)
@ -100,8 +105,10 @@ namespace Fungus.Script
return; return;
} }
FungusVariable variable = fungusScript.gameObject.AddComponent<IntegerVariable>(); Variable variable = new Variable();
variable.key = MakeUniqueKey(fungusScript); variable.key = MakeUniqueKey(fungusScript);
variable.type = VariableType.Integer;
fungusScript.variables.Add(variable);
} }
void AddFloatVariable(object obj) void AddFloatVariable(object obj)
@ -112,8 +119,10 @@ namespace Fungus.Script
return; return;
} }
FungusVariable variable = fungusScript.gameObject.AddComponent<FloatVariable>(); Variable variable = new Variable();
variable.key = MakeUniqueKey(fungusScript); variable.key = MakeUniqueKey(fungusScript);
variable.type = VariableType.Float;
fungusScript.variables.Add(variable);
} }
void AddStringVariable(object obj) void AddStringVariable(object obj)
@ -124,21 +133,21 @@ namespace Fungus.Script
return; return;
} }
FungusVariable variable = fungusScript.gameObject.AddComponent<StringVariable>(); Variable variable = new Variable();
variable.key = MakeUniqueKey(fungusScript); variable.key = MakeUniqueKey(fungusScript);
variable.type = VariableType.String;
fungusScript.variables.Add(variable);
} }
string MakeUniqueKey(FungusScript fungusScript) string MakeUniqueKey(FungusScript fungusScript)
{ {
FungusVariable[] variables = fungusScript.GetComponents<FungusVariable>();
int index = 0; int index = 0;
while (true) while (true)
{ {
string key = "Var" + index; string key = "Var" + index;
bool found = false; bool found = false;
foreach(FungusVariable variable in variables) foreach(Variable variable in fungusScript.variables)
{ {
if (variable.key == key) if (variable.key == key)
{ {

21
Assets/Fungus/Editor/FungusScript/FungusVariableEditor.cs

@ -39,7 +39,25 @@ namespace Fungus.Script
scopeRect.width = width3; scopeRect.width = width3;
string keyValue = EditorGUI.TextField(keyRect, label, keyProp.stringValue); 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); int scopeValue = (int)(VariableScope)EditorGUI.EnumPopup(scopeRect, (VariableScope)scopeProp.enumValueIndex);
if (EditorGUI.EndChangeCheck ()) if (EditorGUI.EndChangeCheck ())
@ -49,7 +67,6 @@ namespace Fungus.Script
keyValue = new string(arr); keyValue = new string(arr);
keyProp.stringValue = keyValue; keyProp.stringValue = keyValue;
typeProp.enumValueIndex = typeValue;
scopeProp.enumValueIndex = scopeValue; scopeProp.enumValueIndex = scopeValue;
} }

Loading…
Cancel
Save