diff --git a/Assets/Fungus/Editor/FungusCommandEditor.cs b/Assets/Fungus/Editor/FungusCommandEditor.cs index ad26320d..01e7e39f 100644 --- a/Assets/Fungus/Editor/FungusCommandEditor.cs +++ b/Assets/Fungus/Editor/FungusCommandEditor.cs @@ -14,7 +14,7 @@ public class FungusCommandEditor : Editor { Rect rect = EditorGUILayout.BeginVertical(); - DrawDefaultInspector(); + DrawCommandInspectorGUI(); FungusCommand t = target as FungusCommand; if (t != null) @@ -36,4 +36,8 @@ public class FungusCommandEditor : Editor EditorGUILayout.EndVertical(); } + public virtual void DrawCommandInspectorGUI() + { + DrawDefaultInspector(); + } } diff --git a/Assets/Fungus/Editor/SequenceControllerEditor.cs b/Assets/Fungus/Editor/SequenceControllerEditor.cs index 1962526d..f4253dd6 100644 --- a/Assets/Fungus/Editor/SequenceControllerEditor.cs +++ b/Assets/Fungus/Editor/SequenceControllerEditor.cs @@ -6,7 +6,7 @@ using Fungus; using Rotorz.ReorderableList; using System.Linq; -[CustomPropertyDrawer (typeof(SequenceController.Variable))] +[CustomPropertyDrawer (typeof(Variable))] public class VariableDrawer : PropertyDrawer { public override void OnGUI (Rect position, SerializedProperty property, GUIContent label) @@ -25,7 +25,7 @@ public class VariableDrawer : PropertyDrawer typeRect.width -= keyRect.width; string keyValue = EditorGUI.TextField(keyRect, label, keyProp.stringValue); - int selectedEnum = (int)(SequenceController.VariableType)EditorGUI.EnumPopup(typeRect, (SequenceController.VariableType)typeProp.enumValueIndex); + int selectedEnum = (int)(VariableType)EditorGUI.EnumPopup(typeRect, (VariableType)typeProp.enumValueIndex); if (EditorGUI.EndChangeCheck ()) { @@ -47,8 +47,7 @@ public class SequenceControllerEditor : Editor void OnEnable() { - globalVariablesProperty = serializedObject.FindProperty("globalVariables"); - localVariablesProperty = serializedObject.FindProperty("localVariables"); + localVariablesProperty = serializedObject.FindProperty("variables"); } public override void OnInspectorGUI() @@ -92,12 +91,9 @@ public class SequenceControllerEditor : Editor EditorGUILayout.LabelField(new GUIContent("Error: Please select a Start Sequence"), style); } - ReorderableListGUI.Title("Local Variables"); + ReorderableListGUI.Title("Variables"); ReorderableListGUI.ListField(localVariablesProperty); - ReorderableListGUI.Title("Global Variables"); - ReorderableListGUI.ListField(globalVariablesProperty); - serializedObject.ApplyModifiedProperties(); } } \ No newline at end of file diff --git a/Assets/Fungus/Editor/SetVariableCommandEditor.cs b/Assets/Fungus/Editor/SetVariableCommandEditor.cs new file mode 100644 index 00000000..c1a35d7f --- /dev/null +++ b/Assets/Fungus/Editor/SetVariableCommandEditor.cs @@ -0,0 +1,15 @@ +using UnityEditor; +using UnityEngine; +using System.Collections; + +[CustomEditor (typeof(SetVariableCommand))] +public class SetVariableCommandEditor : FungusCommandEditor +{ + public override void DrawCommandInspectorGUI() + { + SetVariableCommand t = target as SetVariableCommand; + + t.variableKey = EditorGUILayout.TextField(new GUIContent("Variable Key", "The name of the variable to set"), t.variableKey); + t.booleanValue = EditorGUILayout.Toggle(new GUIContent("Boolean Value", "The boolean value to set the variable with"), t.booleanValue); + } +} diff --git a/Assets/Fungus/Editor/SetVariableCommandEditor.cs.meta b/Assets/Fungus/Editor/SetVariableCommandEditor.cs.meta new file mode 100644 index 00000000..1fd8ee35 --- /dev/null +++ b/Assets/Fungus/Editor/SetVariableCommandEditor.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: d0cbb7e4ccb4a41db8ced7c87070df1d +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Assets/Fungus/Tests/Sequence/SequenceTest.unity b/Assets/Fungus/Tests/Sequence/SequenceTest.unity index 1f2021cc..1ac1f37a 100644 Binary files a/Assets/Fungus/Tests/Sequence/SequenceTest.unity and b/Assets/Fungus/Tests/Sequence/SequenceTest.unity differ diff --git a/Assets/Fungus/VisualScripting/CompareCommand.cs b/Assets/Fungus/VisualScripting/CompareCommand.cs new file mode 100644 index 00000000..da54e28b --- /dev/null +++ b/Assets/Fungus/VisualScripting/CompareCommand.cs @@ -0,0 +1,40 @@ +using UnityEngine; +using System.Collections; +using Fungus; + +public class CompareCommand : FungusCommand +{ + public string variableKey; + + public bool booleanValue; + + public Sequence trueSequence; + + public Sequence falseSequence; + + public override void OnEnter() + { + Variable v = parentSequenceController.GetVariable(variableKey); + if (v != null) + { + if (v.booleanValue == booleanValue) + { + if (trueSequence != null) + { + ExecuteSequence(trueSequence); + return; + } + } + else + { + if (falseSequence != null) + { + ExecuteSequence(falseSequence); + return; + } + } + } + + Finish(); + } +} diff --git a/Assets/Fungus/VisualScripting/CompareCommand.cs.meta b/Assets/Fungus/VisualScripting/CompareCommand.cs.meta new file mode 100644 index 00000000..21288ec4 --- /dev/null +++ b/Assets/Fungus/VisualScripting/CompareCommand.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 050fb9e6e72f442b3b883da8a965bdeb +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Assets/Fungus/VisualScripting/SequenceController.cs b/Assets/Fungus/VisualScripting/SequenceController.cs index e1af17c9..bd4f0c49 100644 --- a/Assets/Fungus/VisualScripting/SequenceController.cs +++ b/Assets/Fungus/VisualScripting/SequenceController.cs @@ -15,25 +15,9 @@ public class SequenceController : MonoBehaviour [System.NonSerialized] public Sequence activeSequence; - - public enum VariableType - { - String, - Integer, - Float, - Boolean - }; - - [Serializable] - public class Variable - { - public string key; - public VariableType type; - } - - public List localVariables = new List(); - public List globalVariables = new List(); + public List variables = new List(); + public void Execute() { if (startSequence == null) @@ -58,4 +42,16 @@ public class SequenceController : MonoBehaviour activeSequence = sequence; sequence.ExecuteNextCommand(); } + + public Variable GetVariable(string key) + { + foreach (Variable v in variables) + { + if (v.key == key) + { + return v; + } + } + return null; + } } diff --git a/Assets/Fungus/VisualScripting/SetVariableCommand.cs b/Assets/Fungus/VisualScripting/SetVariableCommand.cs new file mode 100644 index 00000000..e845cc49 --- /dev/null +++ b/Assets/Fungus/VisualScripting/SetVariableCommand.cs @@ -0,0 +1,51 @@ +using UnityEngine; +using System.Collections; +using Fungus; + +public class SetVariableCommand : FungusCommand +{ + public string variableKey; + + public string stringValue; + + public int integerValue; + + public bool booleanValue; + + public float floatValue; + + public override void OnEnter() + { + if (variableKey.Length == 0) + { + Finish(); + return; + } + + Variable v = parentSequenceController.GetVariable(variableKey); + if (v == null) + { + Debug.LogError("Variable " + variableKey + " not defined."); + } + else + { + switch (v.type) + { + case VariableType.String: + v.stringValue = stringValue; + break; + case VariableType.Integer: + v.integerValue = integerValue; + break; + case VariableType.Float: + v.floatValue = floatValue; + break; + case VariableType.Boolean: + v.booleanValue = booleanValue; + break; + } + } + + Finish(); + } +} diff --git a/Assets/Fungus/VisualScripting/SetVariableCommand.cs.meta b/Assets/Fungus/VisualScripting/SetVariableCommand.cs.meta new file mode 100644 index 00000000..efb68c01 --- /dev/null +++ b/Assets/Fungus/VisualScripting/SetVariableCommand.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: fb77d0ce495044f6e9feb91b31798e8c +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Assets/Fungus/VisualScripting/Variable.cs b/Assets/Fungus/VisualScripting/Variable.cs new file mode 100644 index 00000000..fca441b8 --- /dev/null +++ b/Assets/Fungus/VisualScripting/Variable.cs @@ -0,0 +1,23 @@ +using UnityEngine; +using System; +using System.Collections; + +public enum VariableType +{ + Boolean, + Integer, + Float, + String +}; + +[Serializable] +public class Variable +{ + public string key; + public VariableType type; + + public string stringValue; + public int integerValue; + public float floatValue; + public bool booleanValue; +} diff --git a/Assets/Fungus/VisualScripting/Variable.cs.meta b/Assets/Fungus/VisualScripting/Variable.cs.meta new file mode 100644 index 00000000..c02059a0 --- /dev/null +++ b/Assets/Fungus/VisualScripting/Variable.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 2f3853d313cd94fe184e3478cefc11f2 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Assets/Fungus/VisualScripting/WaitCommand.cs b/Assets/Fungus/VisualScripting/WaitCommand.cs index dc91517d..fe761468 100644 --- a/Assets/Fungus/VisualScripting/WaitCommand.cs +++ b/Assets/Fungus/VisualScripting/WaitCommand.cs @@ -1,7 +1,6 @@ using UnityEngine; using System; using System.Collections; -using System.Collections.Generic; namespace Fungus {