|
|
|
@ -12,7 +12,7 @@ namespace Fungus.Script
|
|
|
|
|
public class FungusScriptEditor : Editor |
|
|
|
|
{ |
|
|
|
|
SerializedProperty variablesProperty; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void OnEnable() |
|
|
|
|
{ |
|
|
|
|
if (serializedObject != null) |
|
|
|
@ -20,18 +20,18 @@ namespace Fungus.Script
|
|
|
|
|
variablesProperty = serializedObject.FindProperty("variables"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void OnInspectorUpdate() |
|
|
|
|
{ |
|
|
|
|
Repaint(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public override void OnInspectorGUI() |
|
|
|
|
{ |
|
|
|
|
serializedObject.Update(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FungusScript t = target as FungusScript; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GUILayout.BeginHorizontal(); |
|
|
|
|
GUILayout.FlexibleSpace(); |
|
|
|
|
if (GUILayout.Button("Open Fungus Editor")) |
|
|
|
@ -50,33 +50,33 @@ namespace Fungus.Script
|
|
|
|
|
Undo.RegisterCreatedObjectUndo(go, "Sequence"); |
|
|
|
|
Selection.activeGameObject = go; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GUILayout.FlexibleSpace(); |
|
|
|
|
GUILayout.EndHorizontal(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GUIContent stepTimeLabel = new GUIContent("Step Time", "Minimum time to execute each step"); |
|
|
|
|
t.stepTime = EditorGUILayout.FloatField(stepTimeLabel, t.stepTime); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GUIContent startSequenceLabel = new GUIContent("Start Sequence", "Sequence to be executed when controller starts."); |
|
|
|
|
t.startSequence = SequenceEditor.SequenceField(startSequenceLabel, t, t.startSequence); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GUIContent startAutomaticallyLabel = new GUIContent("Start Automatically", "Start this Fungus Script when the scene starts."); |
|
|
|
|
t.startAutomatically = EditorGUILayout.Toggle(startAutomaticallyLabel, t.startAutomatically); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (t.startSequence == null) |
|
|
|
|
{ |
|
|
|
|
GUIStyle style = new GUIStyle(GUI.skin.label); |
|
|
|
|
style.normal.textColor = new Color(1,0,0); |
|
|
|
|
EditorGUILayout.LabelField(new GUIContent("Error: Please select a Start Sequence"), style); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
serializedObject.ApplyModifiedProperties(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void DrawVariablesGUI() |
|
|
|
|
{ |
|
|
|
|
serializedObject.Update(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FungusScript t = target as FungusScript; |
|
|
|
|
|
|
|
|
|
ReorderableListGUI.Title("Variables"); |
|
|
|
@ -86,66 +86,24 @@ namespace Fungus.Script
|
|
|
|
|
|
|
|
|
|
GUILayout.BeginHorizontal(); |
|
|
|
|
GUILayout.FlexibleSpace(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!Application.isPlaying && 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.AddItem(new GUIContent ("Boolean"), false, AddVariable<BooleanVariable>, t); |
|
|
|
|
menu.AddItem (new GUIContent ("Integer"), false, AddVariable<IntegerVariable>, t); |
|
|
|
|
menu.AddItem (new GUIContent ("Float"), false, AddVariable<FloatVariable>, t); |
|
|
|
|
menu.AddItem (new GUIContent ("String"), false, AddVariable<StringVariable>, t); |
|
|
|
|
|
|
|
|
|
menu.ShowAsContext (); |
|
|
|
|
} |
|
|
|
|
GUILayout.EndHorizontal(); |
|
|
|
|
|
|
|
|
|
serializedObject.ApplyModifiedProperties(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void AddBooleanVariable(object obj) |
|
|
|
|
{ |
|
|
|
|
FungusScript fungusScript = obj as FungusScript; |
|
|
|
|
if (fungusScript == null) |
|
|
|
|
{ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Undo.RecordObject(fungusScript, "Add Boolean"); |
|
|
|
|
BooleanVariable variable = fungusScript.gameObject.AddComponent<BooleanVariable>(); |
|
|
|
|
variable.key = MakeUniqueKey(fungusScript); |
|
|
|
|
fungusScript.variables.Add(variable); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void AddIntegerVariable(object obj) |
|
|
|
|
{ |
|
|
|
|
FungusScript fungusScript = obj as FungusScript; |
|
|
|
|
if (fungusScript == null) |
|
|
|
|
{ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Undo.RecordObject(fungusScript, "Add Integer"); |
|
|
|
|
IntegerVariable variable = fungusScript.gameObject.AddComponent<IntegerVariable>(); |
|
|
|
|
variable.key = MakeUniqueKey(fungusScript); |
|
|
|
|
fungusScript.variables.Add(variable); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void AddFloatVariable(object obj) |
|
|
|
|
{ |
|
|
|
|
FungusScript fungusScript = obj as FungusScript; |
|
|
|
|
if (fungusScript == null) |
|
|
|
|
{ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Undo.RecordObject(fungusScript, "Add Float"); |
|
|
|
|
FloatVariable variable = fungusScript.gameObject.AddComponent<FloatVariable>(); |
|
|
|
|
variable.key = MakeUniqueKey(fungusScript); |
|
|
|
|
fungusScript.variables.Add(variable); |
|
|
|
|
serializedObject.ApplyModifiedProperties(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void AddStringVariable(object obj) |
|
|
|
|
|
|
|
|
|
void AddVariable<T>(object obj) where T : FungusVariable |
|
|
|
|
{ |
|
|
|
|
FungusScript fungusScript = obj as FungusScript; |
|
|
|
|
if (fungusScript == null) |
|
|
|
@ -153,8 +111,8 @@ namespace Fungus.Script
|
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Undo.RecordObject(fungusScript, "Add String"); |
|
|
|
|
StringVariable variable = fungusScript.gameObject.AddComponent<StringVariable>(); |
|
|
|
|
Undo.RecordObject(fungusScript, "Add Variable"); |
|
|
|
|
T variable = fungusScript.gameObject.AddComponent<T>(); |
|
|
|
|
variable.key = MakeUniqueKey(fungusScript); |
|
|
|
|
fungusScript.variables.Add(variable); |
|
|
|
|
} |
|
|
|
@ -165,7 +123,7 @@ namespace Fungus.Script
|
|
|
|
|
while (true) |
|
|
|
|
{ |
|
|
|
|
string key = "Var" + index; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool found = false; |
|
|
|
|
foreach(FungusVariable variable in fungusScript.GetComponents<FungusVariable>()) |
|
|
|
|
{ |
|
|
|
@ -175,7 +133,7 @@ namespace Fungus.Script
|
|
|
|
|
index++; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!found) |
|
|
|
|
{ |
|
|
|
|
return key; |
|
|
|
@ -183,5 +141,5 @@ namespace Fungus.Script
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |