From 5b725896a3b61b5a06e72b8bd09c2f279e88853d Mon Sep 17 00:00:00 2001 From: chrisgregan Date: Thu, 7 Aug 2014 15:04:15 +0100 Subject: [PATCH] Variables are now components --- .../Editor/FungusScript/AddOptionEditor.cs | 14 +- .../Editor/FungusScript/FungusScriptEditor.cs | 23 +-- .../Fungus/Editor/FungusScript/JumpEditor.cs | 52 +++---- .../Fungus/Editor/FungusScript/SayEditor.cs | 14 +- .../Editor/FungusScript/SequenceEditor.cs | 41 +++--- .../Fungus/Editor/FungusScript/SetEditor.cs | 64 ++++---- .../Editor/FungusScript/VariablesWindow.cs | 48 +++--- Assets/Fungus/VisualScripting/AddOption.cs | 9 +- .../Fungus/VisualScripting/BooleanVariable.cs | 18 +++ .../VisualScripting/BooleanVariable.cs.meta | 8 + .../Fungus/VisualScripting/FloatVariable.cs | 18 +++ .../VisualScripting/FloatVariable.cs.meta | 8 + Assets/Fungus/VisualScripting/FungusScript.cs | 14 -- .../Fungus/VisualScripting/IntegerVariable.cs | 18 +++ .../VisualScripting/IntegerVariable.cs.meta | 8 + Assets/Fungus/VisualScripting/Jump.cs | 61 ++++---- Assets/Fungus/VisualScripting/Say.cs | 9 +- Assets/Fungus/VisualScripting/Set.cs | 137 +++++++++--------- .../Fungus/VisualScripting/StringVariable.cs | 18 +++ .../VisualScripting/StringVariable.cs.meta | 8 + Assets/Fungus/VisualScripting/Variable.cs | 66 +-------- Assets/Shuttle/ShuttleGame.unity | Bin 77868 -> 79052 bytes 22 files changed, 336 insertions(+), 320 deletions(-) create mode 100644 Assets/Fungus/VisualScripting/BooleanVariable.cs create mode 100644 Assets/Fungus/VisualScripting/BooleanVariable.cs.meta create mode 100644 Assets/Fungus/VisualScripting/FloatVariable.cs create mode 100644 Assets/Fungus/VisualScripting/FloatVariable.cs.meta create mode 100644 Assets/Fungus/VisualScripting/IntegerVariable.cs create mode 100644 Assets/Fungus/VisualScripting/IntegerVariable.cs.meta create mode 100644 Assets/Fungus/VisualScripting/StringVariable.cs create mode 100644 Assets/Fungus/VisualScripting/StringVariable.cs.meta diff --git a/Assets/Fungus/Editor/FungusScript/AddOptionEditor.cs b/Assets/Fungus/Editor/FungusScript/AddOptionEditor.cs index a2107d43..3a4fb362 100644 --- a/Assets/Fungus/Editor/FungusScript/AddOptionEditor.cs +++ b/Assets/Fungus/Editor/FungusScript/AddOptionEditor.cs @@ -20,17 +20,15 @@ namespace Fungus.Script Sequence targetSequence = SequenceEditor.SequenceField(new GUIContent("Target Sequence", "Sequence to execute when option is selected"), t.GetFungusScript(), t.targetSequence); AddOption.ShowCondition showCondition = (AddOption.ShowCondition)EditorGUILayout.EnumPopup(new GUIContent("Show Condition", "Condition when this option should be visible."), t.showCondition); - string booleanVariableKey = t.booleanVariableKey; + BooleanVariable booleanVariable = t.booleanVariable; if (showCondition == AddOption.ShowCondition.BooleanIsFalse || showCondition == AddOption.ShowCondition.BooleanIsTrue) { - VariableType type = VariableType.Boolean; - booleanVariableKey = SequenceEditor.VariableField (new GUIContent ("Boolean Variable", "Boolean variable to test for condition"), - t.GetFungusScript (), - t.booleanVariableKey, - ref type, - v => { return v.type == VariableType.Boolean; }); + booleanVariable = SequenceEditor.VariableField (new GUIContent ("Boolean Variable", "Boolean variable to test for condition"), + t.GetFungusScript (), + t.booleanVariable, + v => { return v.GetType() == typeof(BooleanVariable); }) as BooleanVariable; } if (EditorGUI.EndChangeCheck()) @@ -39,7 +37,7 @@ namespace Fungus.Script t.optionText = optionText; t.targetSequence = targetSequence; t.showCondition = showCondition; - t.booleanVariableKey = booleanVariableKey; + t.booleanVariable = booleanVariable; } } } diff --git a/Assets/Fungus/Editor/FungusScript/FungusScriptEditor.cs b/Assets/Fungus/Editor/FungusScript/FungusScriptEditor.cs index fcb39251..28b49ba4 100644 --- a/Assets/Fungus/Editor/FungusScript/FungusScriptEditor.cs +++ b/Assets/Fungus/Editor/FungusScript/FungusScriptEditor.cs @@ -3,12 +3,12 @@ using UnityEngine; using System.Collections; using System.Collections.Generic; using Fungus; -using Rotorz.ReorderableList; -using System.Linq; +//using Rotorz.ReorderableList; +//using System.Linq; namespace Fungus.Script { - + /* [CustomPropertyDrawer (typeof(Variable))] public class VariableDrawer : PropertyDrawer { @@ -56,20 +56,21 @@ namespace Fungus.Script EditorGUI.EndProperty(); } } + */ [CustomEditor (typeof(FungusScript))] public class FungusScriptEditor : Editor { SerializedProperty variablesProperty; - void OnEnable() - { - variablesProperty = serializedObject.FindProperty("variables"); - } + //void OnEnable() + //{ + // variablesProperty = serializedObject.FindProperty("variables"); + //} public override void OnInspectorGUI() { - serializedObject.Update(); + //serializedObject.Update(); FungusScript t = target as FungusScript; @@ -111,10 +112,10 @@ namespace Fungus.Script EditorGUILayout.LabelField(new GUIContent("Error: Please select a Start Sequence"), style); } - ReorderableListGUI.Title("Variables"); - ReorderableListGUI.ListField(variablesProperty); + //ReorderableListGUI.Title("Variables"); + //ReorderableListGUI.ListField(variablesProperty); - serializedObject.ApplyModifiedProperties(); + //serializedObject.ApplyModifiedProperties(); } } diff --git a/Assets/Fungus/Editor/FungusScript/JumpEditor.cs b/Assets/Fungus/Editor/FungusScript/JumpEditor.cs index 6c8afbd6..70cee6c2 100644 --- a/Assets/Fungus/Editor/FungusScript/JumpEditor.cs +++ b/Assets/Fungus/Editor/FungusScript/JumpEditor.cs @@ -36,43 +36,28 @@ namespace Fungus.Script } return; } - - List keys = new List(); - keys.Add(""); - int index = 0; - for (int i = 0; i < sc.variables.Count; ++i) - { - Variable v = sc.variables[i]; - keys.Add(v.key); - if (v.key == t.variableKey && - index == 0) - { - index = i + 1; - } - } - - int newIndex = EditorGUILayout.Popup("Compare Variable", index, keys.ToArray()); - bool keyChanged = (t.variableKey != keys[newIndex]); + FungusVariable fungusVariable = SequenceEditor.VariableField(new GUIContent("Compare Variable", "Variable to use in compare operation"), + t.GetFungusScript(), + t.variable, + null); - if (keyChanged) + if (fungusVariable != t.variable) { Undo.RecordObject(t, "Select variable"); - t.variableKey = keys[newIndex]; + t.variable = fungusVariable; } - if (t.variableKey == "") + if (t.variable == null) { return; } - VariableType variableType = sc.variables[newIndex - 1].type; - List operatorList = new List(); operatorList.Add(new GUIContent("==")); operatorList.Add(new GUIContent("!=")); - if (variableType == VariableType.Integer || - variableType == VariableType.Float) + if (t.variable.GetType() == typeof(IntegerVariable) || + t.variable.GetType() == typeof(FloatVariable)) { operatorList.Add(new GUIContent("<")); operatorList.Add(new GUIContent(">")); @@ -95,20 +80,21 @@ namespace Fungus.Script float floatValue = t.floatData.value; string stringValue = t.stringData.value; - switch (variableType) + if (t.variable.GetType() == typeof(BooleanVariable)) { - case VariableType.Boolean: booleanValue = EditorGUILayout.Toggle(new GUIContent("Boolean Value", "The boolean value to set the variable with"), booleanValue); - break; - case VariableType.Integer: + } + else if (t.variable.GetType() == typeof(IntegerVariable)) + { integerValue = EditorGUILayout.IntField(new GUIContent("Integer Value", "The integer value to set the variable with"), integerValue); - break; - case VariableType.Float: + } + else if (t.variable.GetType() == typeof(FloatVariable)) + { floatValue = EditorGUILayout.FloatField(new GUIContent("Float Value", "The float value to set the variable with"), floatValue); - break; - case VariableType.String: + } + else if (t.variable.GetType() == typeof(StringVariable)) + { stringValue = EditorGUILayout.TextField(new GUIContent("String Value", "The string value to set the variable with"), stringValue); - break; } if (booleanValue != t.booleanData.value) diff --git a/Assets/Fungus/Editor/FungusScript/SayEditor.cs b/Assets/Fungus/Editor/FungusScript/SayEditor.cs index 44510692..408b8def 100644 --- a/Assets/Fungus/Editor/FungusScript/SayEditor.cs +++ b/Assets/Fungus/Editor/FungusScript/SayEditor.cs @@ -24,17 +24,15 @@ namespace Fungus.Script Say.ShowCondition showCondition = (Say.ShowCondition)EditorGUILayout.EnumPopup(new GUIContent("Show Condition", "Condition when this say text should be visible."), t.showCondition); - string booleanVariableKey = t.booleanVariableKey; + BooleanVariable booleanVariable = t.booleanVariable; if (showCondition == Say.ShowCondition.BooleanIsFalse || showCondition == Say.ShowCondition.BooleanIsTrue) { - VariableType type = VariableType.Boolean; - booleanVariableKey = SequenceEditor.VariableField (new GUIContent ("Boolean Variable", "Boolean variable to test for condition"), - t.GetFungusScript (), - t.booleanVariableKey, - ref type, - v => { return v.type == VariableType.Boolean; }); + booleanVariable = SequenceEditor.VariableField (new GUIContent ("Boolean Variable", "Boolean variable to test for condition"), + t.GetFungusScript (), + t.booleanVariable, + v => { return v.GetType() == typeof(BooleanVariable); }) as BooleanVariable; } if (EditorGUI.EndChangeCheck()) @@ -43,7 +41,7 @@ namespace Fungus.Script t.character = character; t.text = text; t.showCondition = showCondition; - t.booleanVariableKey = booleanVariableKey; + t.booleanVariable = booleanVariable; } } diff --git a/Assets/Fungus/Editor/FungusScript/SequenceEditor.cs b/Assets/Fungus/Editor/FungusScript/SequenceEditor.cs index 15c373c0..8cb74e4e 100644 --- a/Assets/Fungus/Editor/FungusScript/SequenceEditor.cs +++ b/Assets/Fungus/Editor/FungusScript/SequenceEditor.cs @@ -3,6 +3,7 @@ using UnityEngine; using System; using System.Collections; using System.Collections.Generic; +using System.Linq; namespace Fungus.Script { @@ -48,15 +49,19 @@ namespace Fungus.Script return result; } - static public string VariableField(GUIContent label, FungusScript fungusScript, string variableKey, ref VariableType variableType, Func filter = null) + static public FungusVariable VariableField(GUIContent label, FungusScript fungusScript, FungusVariable variable, Func filter = null) { - List keys = new List(); - keys.Add(""); + List variableKeys = new List(); + List variableObjects = new List(); + + variableKeys.Add(""); + variableObjects.Add(null); + + FungusVariable[] variables = fungusScript.GetComponents(); int index = 0; - for (int i = 0; i < fungusScript.variables.Count; ++i) + int selectedIndex = 0; + foreach (FungusVariable v in variables) { - Variable v = fungusScript.variables[i]; - if (filter != null) { if (!filter(v)) @@ -65,22 +70,20 @@ namespace Fungus.Script } } - keys.Add(v.key); - if (v.key == variableKey && - index == 0) + variableKeys.Add(v.key); + variableObjects.Add(v); + + index++; + + if (v == variable) { - index = i + 1; + selectedIndex = index; } } - - int newIndex = EditorGUILayout.Popup(label.text, index, keys.ToArray()); - - if (newIndex > 0) - { - variableType = fungusScript.variables[newIndex - 1].type; - } - - return keys[newIndex]; + + selectedIndex = EditorGUILayout.Popup(label.text, selectedIndex, variableKeys.ToArray()); + + return variableObjects[selectedIndex]; } } diff --git a/Assets/Fungus/Editor/FungusScript/SetEditor.cs b/Assets/Fungus/Editor/FungusScript/SetEditor.cs index d3604e0f..a6529b88 100644 --- a/Assets/Fungus/Editor/FungusScript/SetEditor.cs +++ b/Assets/Fungus/Editor/FungusScript/SetEditor.cs @@ -19,37 +19,34 @@ namespace Fungus.Script return; } - VariableType variableType = VariableType.Boolean; - string variableKey = SequenceEditor.VariableField(new GUIContent("Variable", "Variable to set"), - fungusScript, - t.variableKey, - ref variableType); - - - if (variableKey != t.variableKey) + FungusVariable variable = SequenceEditor.VariableField(new GUIContent("Variable", "Variable to set"), + fungusScript, + t.variable); + + if (variable != t.variable) { Undo.RecordObject(t, "Set Variable Key"); - t.variableKey = variableKey; + t.variable = variable; } - if (t.variableKey == "") + if (t.variable == null) { return; } List operatorsList = new List(); operatorsList.Add(new GUIContent("=")); - if (variableType == VariableType.Boolean) + if (variable.GetType() == typeof(BooleanVariable)) { operatorsList.Add(new GUIContent("!")); } - else if (variableType == VariableType.Integer || - variableType == VariableType.Float) + else if (variable.GetType() == typeof(IntegerVariable) || + variable.GetType() == typeof(FloatVariable)) { - operatorsList.Add(new GUIContent("+")); - operatorsList.Add(new GUIContent("-")); - operatorsList.Add(new GUIContent("*")); - operatorsList.Add(new GUIContent("/")); + operatorsList.Add(new GUIContent("+")); + operatorsList.Add(new GUIContent("-")); + operatorsList.Add(new GUIContent("*")); + operatorsList.Add(new GUIContent("/")); } int selectedIndex = 0; @@ -79,11 +76,9 @@ namespace Fungus.Script selectedIndex = EditorGUILayout.Popup(new GUIContent("Operator", "Arithmetic operator to use"), selectedIndex, operatorsList.ToArray()); Set.SetOperator setOperator = Set.SetOperator.Assign; - switch (variableType) + if (variable.GetType() == typeof(BooleanVariable) || + variable.GetType() == typeof(StringVariable)) { - default: - case VariableType.Boolean: - case VariableType.String: switch (selectedIndex) { default: @@ -94,9 +89,10 @@ namespace Fungus.Script setOperator = Set.SetOperator.Negate; break; } - break; - case VariableType.Integer: - case VariableType.Float: + } + else if (variable.GetType() == typeof(IntegerVariable) || + variable.GetType() == typeof(FloatVariable)) + { switch (selectedIndex) { default: @@ -116,7 +112,6 @@ namespace Fungus.Script setOperator = Set.SetOperator.Divide; break; } - break; } if (setOperator != t.setOperator) @@ -130,20 +125,21 @@ namespace Fungus.Script float floatValue = t.floatData.value; string stringValue = t.stringData.value; - switch (variableType) + if (variable.GetType() == typeof(BooleanVariable)) { - case VariableType.Boolean: booleanValue = EditorGUILayout.Toggle(new GUIContent("Boolean Value", "The boolean value to set the variable with"), booleanValue); - break; - case VariableType.Integer: + } + else if (variable.GetType() == typeof(IntegerVariable)) + { integerValue = EditorGUILayout.IntField(new GUIContent("Integer Value", "The integer value to set the variable with"), integerValue); - break; - case VariableType.Float: + } + else if (variable.GetType() == typeof(FloatVariable)) + { floatValue = EditorGUILayout.FloatField(new GUIContent("Float Value", "The float value to set the variable with"), floatValue); - break; - case VariableType.String: + } + else if (variable.GetType() == typeof(StringVariable)) + { stringValue = EditorGUILayout.TextField(new GUIContent("String Value", "The string value to set the variable with"), stringValue); - break; } if (booleanValue != t.booleanData.value) diff --git a/Assets/Fungus/Editor/FungusScript/VariablesWindow.cs b/Assets/Fungus/Editor/FungusScript/VariablesWindow.cs index 3177a839..1ca3e099 100644 --- a/Assets/Fungus/Editor/FungusScript/VariablesWindow.cs +++ b/Assets/Fungus/Editor/FungusScript/VariablesWindow.cs @@ -27,24 +27,25 @@ namespace Fungus.Script } // Warn about conflicting global variable types - Dictionary globalTypes = new Dictionary(); + Dictionary globals = new Dictionary(); FungusScript[] fungusScripts = GameObject.FindObjectsOfType(); foreach (FungusScript fs in fungusScripts) { - foreach (Variable v in fs.variables) + FungusVariable[] variables = fs.GetComponents(); + foreach (FungusVariable v in variables) { if (v.scope == VariableScope.Global) { - if (globalTypes.ContainsKey(v.key)) + if (globals.ContainsKey(v.key)) { - if (globalTypes[v.key] != v.type) + if (globals[v.key].GetType() != v.GetType()) { GUIStyle errorStyle = new GUIStyle(GUI.skin.label); errorStyle.normal.textColor = new Color(1,0,0); GUILayout.Label("Error: Global '" + v.key + "' must use the same type in all scripts.", errorStyle); } } - globalTypes[v.key] = v.type; + globals[v.key] = v; } } } @@ -71,7 +72,8 @@ namespace Fungus.Script boxStyle.margin.top = 0; boxStyle.margin.bottom = 0; - foreach (Variable variable in fungusScript.variables) + FungusVariable[] fsVariables = fungusScript.GetComponents(); + foreach (FungusVariable variable in fsVariables) { GUILayout.BeginHorizontal(boxStyle); @@ -91,33 +93,31 @@ namespace Fungus.Script break; } - switch (variable.type) + if (variable.GetType() == typeof(BooleanVariable)) { - case VariableType.Boolean: typeString = "Boolean"; - valueString = variable.BooleanValue ? "True" : "False"; - break; - case VariableType.Integer: + valueString = (variable as BooleanVariable).Value ? "True" : "False"; + } + else if (variable.GetType() == typeof(IntegerVariable)) + { typeString = "Integer"; - valueString = variable.IntegerValue.ToString(); - break; - case VariableType.Float: + valueString = (variable as IntegerVariable).Value.ToString(); + } + else if (variable.GetType() == typeof(FloatVariable)) + { typeString = "Float"; - valueString = variable.FloatValue.ToString(); - break; - case VariableType.String: + valueString = (variable as FloatVariable).Value.ToString(); + } + else if (variable.GetType() == typeof(StringVariable)) + { typeString = "String"; + valueString = (variable as StringVariable).Value; - if (variable.StringValue == null || - variable.StringValue.Length == 0) + if (valueString == null || + valueString.Length == 0) { valueString = "\"\""; } - else - { - valueString = variable.StringValue; - } - break; } GUILayout.Label(keyString, GUILayout.Width(columnWidth)); diff --git a/Assets/Fungus/VisualScripting/AddOption.cs b/Assets/Fungus/VisualScripting/AddOption.cs index f9a40566..d1d5c5bb 100644 --- a/Assets/Fungus/VisualScripting/AddOption.cs +++ b/Assets/Fungus/VisualScripting/AddOption.cs @@ -18,7 +18,7 @@ namespace Fungus.Script public string optionText; public Sequence targetSequence; public ShowCondition showCondition; - public string booleanVariableKey; + public BooleanVariable booleanVariable; public override void OnEnter() { @@ -39,20 +39,19 @@ namespace Fungus.Script } else { - Variable v = parentFungusScript.GetVariable(booleanVariableKey); - if (v == null) + if (booleanVariable == null) { showOption = false; } else { if (showCondition == ShowCondition.BooleanIsTrue && - v.BooleanValue != true) + booleanVariable.Value != true) { showOption = false; } else if (showCondition == ShowCondition.BooleanIsFalse && - v.BooleanValue != false) + booleanVariable.Value != false) { showOption = false; } diff --git a/Assets/Fungus/VisualScripting/BooleanVariable.cs b/Assets/Fungus/VisualScripting/BooleanVariable.cs new file mode 100644 index 00000000..2c5de2be --- /dev/null +++ b/Assets/Fungus/VisualScripting/BooleanVariable.cs @@ -0,0 +1,18 @@ +using UnityEngine; +using System.Collections; + +namespace Fungus.Script +{ + + public class BooleanVariable : FungusVariable + { + bool booleanValue; + + public bool Value + { + get { return (scope == VariableScope.Local) ? booleanValue : Variables.GetBoolean(key); } + set { if (scope == VariableScope.Local) { booleanValue = value; } else { Variables.SetBoolean(key, value); } } + } + } + +} \ No newline at end of file diff --git a/Assets/Fungus/VisualScripting/BooleanVariable.cs.meta b/Assets/Fungus/VisualScripting/BooleanVariable.cs.meta new file mode 100644 index 00000000..c32e891e --- /dev/null +++ b/Assets/Fungus/VisualScripting/BooleanVariable.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 5d02d9822eec54c98afe95bb497211b3 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Assets/Fungus/VisualScripting/FloatVariable.cs b/Assets/Fungus/VisualScripting/FloatVariable.cs new file mode 100644 index 00000000..8782690c --- /dev/null +++ b/Assets/Fungus/VisualScripting/FloatVariable.cs @@ -0,0 +1,18 @@ +using UnityEngine; +using System.Collections; + +namespace Fungus.Script +{ + + public class FloatVariable : FungusVariable + { + float floatValue; + + public float Value + { + get { return (scope == VariableScope.Local) ? floatValue : Variables.GetFloat(key); } + set { if (scope == VariableScope.Local) { floatValue = value; } else { Variables.SetFloat(key, value); } } + } + } + +} \ No newline at end of file diff --git a/Assets/Fungus/VisualScripting/FloatVariable.cs.meta b/Assets/Fungus/VisualScripting/FloatVariable.cs.meta new file mode 100644 index 00000000..a229b440 --- /dev/null +++ b/Assets/Fungus/VisualScripting/FloatVariable.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 705fa1ac97df74e3a84ff952ffd923f1 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Assets/Fungus/VisualScripting/FungusScript.cs b/Assets/Fungus/VisualScripting/FungusScript.cs index 2b59ad52..9a23ec4a 100644 --- a/Assets/Fungus/VisualScripting/FungusScript.cs +++ b/Assets/Fungus/VisualScripting/FungusScript.cs @@ -18,8 +18,6 @@ namespace Fungus.Script [System.NonSerialized] public Sequence activeSequence; - public List variables = new List(); - public bool startAutomatically = false; void Start() @@ -54,18 +52,6 @@ namespace Fungus.Script activeSequence = sequence; sequence.ExecuteNextCommand(); } - - public Variable GetVariable(string key) - { - foreach (Variable v in variables) - { - if (v.key == key) - { - return v; - } - } - return null; - } } } \ No newline at end of file diff --git a/Assets/Fungus/VisualScripting/IntegerVariable.cs b/Assets/Fungus/VisualScripting/IntegerVariable.cs new file mode 100644 index 00000000..f4aab4a8 --- /dev/null +++ b/Assets/Fungus/VisualScripting/IntegerVariable.cs @@ -0,0 +1,18 @@ +using UnityEngine; +using System.Collections; + +namespace Fungus.Script +{ + + public class IntegerVariable : FungusVariable + { + int integerValue; + + public int Value + { + get { return (scope == VariableScope.Local) ? integerValue : Variables.GetInteger(key); } + set { if (scope == VariableScope.Local) { integerValue = value; } else { Variables.SetInteger(key, value); } } + } + } + +} \ No newline at end of file diff --git a/Assets/Fungus/VisualScripting/IntegerVariable.cs.meta b/Assets/Fungus/VisualScripting/IntegerVariable.cs.meta new file mode 100644 index 00000000..300d977e --- /dev/null +++ b/Assets/Fungus/VisualScripting/IntegerVariable.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: afb91b566ceda411bad1e9d3c3243ecc +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Assets/Fungus/VisualScripting/Jump.cs b/Assets/Fungus/VisualScripting/Jump.cs index c9ed145f..f6ae3b85 100644 --- a/Assets/Fungus/VisualScripting/Jump.cs +++ b/Assets/Fungus/VisualScripting/Jump.cs @@ -26,7 +26,7 @@ namespace Fungus.Script public Sequence targetSequence; // Only used for Always condition - public string variableKey; + public FungusVariable variable; public CompareOperator compareOperator; @@ -51,82 +51,87 @@ namespace Fungus.Script return; } - Variable v = parentFungusScript.GetVariable(variableKey); - bool condition = false; - switch (v.type) + if (variable == null) + { + Continue(); + return; + } + + if (variable.GetType() == typeof(BooleanVariable)) { - case VariableType.Boolean: switch (compareOperator) { case CompareOperator.Equals: - condition = (v.BooleanValue == booleanData.value); + condition = (variable as BooleanVariable).Value == booleanData.value; break; case CompareOperator.NotEquals: default: - condition = (v.BooleanValue != booleanData.value); + condition = (variable as BooleanVariable).Value != booleanData.value; break; } - break; - case VariableType.Integer: + } + else if (variable.GetType() == typeof(IntegerVariable)) + { switch (compareOperator) { case CompareOperator.Equals: - condition = (v.IntegerValue == integerData.value); + condition = (variable as IntegerVariable).Value == integerData.value; break; case CompareOperator.NotEquals: - condition = (v.IntegerValue != integerData.value); + condition = (variable as IntegerVariable).Value != integerData.value; break; case CompareOperator.LessThan: - condition = (v.IntegerValue < integerData.value); + condition = (variable as IntegerVariable).Value < integerData.value; break; case CompareOperator.GreaterThan: - condition = (v.IntegerValue > integerData.value); + condition = (variable as IntegerVariable).Value > integerData.value; break; case CompareOperator.LessThanOrEquals: - condition = (v.IntegerValue <= integerData.value); + condition = (variable as IntegerVariable).Value <= integerData.value; break; case CompareOperator.GreaterThanOrEquals: - condition = (v.IntegerValue >= integerData.value); + condition = (variable as IntegerVariable).Value >= integerData.value; break; } - break; - case VariableType.Float: + } + else if (variable.GetType() == typeof(FloatVariable)) + { switch (compareOperator) { case CompareOperator.Equals: - condition = (v.FloatValue == floatData.value); + condition = (variable as FloatVariable).Value == floatData.value; break; case CompareOperator.NotEquals: - condition = (v.FloatValue != floatData.value); + condition = (variable as FloatVariable).Value != floatData.value; break; case CompareOperator.LessThan: - condition = (v.FloatValue < floatData.value); + condition = (variable as FloatVariable).Value < floatData.value; break; case CompareOperator.GreaterThan: - condition = (v.FloatValue > floatData.value); + condition = (variable as FloatVariable).Value > floatData.value; break; case CompareOperator.LessThanOrEquals: - condition = (v.FloatValue <= floatData.value); + condition = (variable as FloatVariable).Value <= floatData.value; break; case CompareOperator.GreaterThanOrEquals: - condition = (v.FloatValue >= floatData.value); + condition = (variable as FloatVariable).Value >= floatData.value; break; } - break; - case VariableType.String: + } + else if (variable.GetType() == typeof(StringVariable)) + { switch (compareOperator) { case CompareOperator.Equals: - condition = (v.StringValue == stringData.value); + condition = (variable as StringVariable).Value == stringData.value; break; case CompareOperator.NotEquals: default: - condition = (v.StringValue != stringData.value); + condition = (variable as StringVariable).Value != stringData.value; break; } - break; } if (condition) diff --git a/Assets/Fungus/VisualScripting/Say.cs b/Assets/Fungus/VisualScripting/Say.cs index 0e34b2bc..28e14c21 100644 --- a/Assets/Fungus/VisualScripting/Say.cs +++ b/Assets/Fungus/VisualScripting/Say.cs @@ -18,7 +18,7 @@ namespace Fungus.Script public string character; public string text; public ShowCondition showCondition; - public string booleanVariableKey; + public BooleanVariable booleanVariable; int executionCount; @@ -46,20 +46,19 @@ namespace Fungus.Script } else { - Variable v = parentFungusScript.GetVariable(booleanVariableKey); - if (v == null) + if (booleanVariable == null) { showSayText = false; } else { if (showCondition == ShowCondition.BooleanIsTrue && - v.BooleanValue != true) + booleanVariable.Value != true) { showSayText = false; } else if (showCondition == ShowCondition.BooleanIsFalse && - v.BooleanValue != false) + booleanVariable.Value != false) { showSayText = false; } diff --git a/Assets/Fungus/VisualScripting/Set.cs b/Assets/Fungus/VisualScripting/Set.cs index 7fed6d32..8f0f90ae 100644 --- a/Assets/Fungus/VisualScripting/Set.cs +++ b/Assets/Fungus/VisualScripting/Set.cs @@ -16,7 +16,7 @@ namespace Fungus.Script Divide // / } - public string variableKey; + public FungusVariable variable; public SetOperator setOperator; @@ -30,89 +30,82 @@ namespace Fungus.Script public override void OnEnter() { - if (variableKey.Length == 0) + if (variable == null) { Continue(); return; } - Variable v = parentFungusScript.GetVariable(variableKey); - if (v == null) + if (variable.GetType() == typeof(BooleanVariable)) { - Debug.LogError("Variable " + variableKey + " not defined."); + switch (setOperator) + { + default: + case SetOperator.Assign: + (variable as BooleanVariable).Value = booleanData.value; + break; + case SetOperator.Negate: + (variable as BooleanVariable).Value = !booleanData.value; + break; + } } - else + else if (variable.GetType() == typeof(IntegerVariable)) { - switch (v.type) + switch (setOperator) { - case VariableType.Boolean: - switch (setOperator) - { - default: - case SetOperator.Assign: - v.BooleanValue = booleanData.value; - break; - case SetOperator.Negate: - v.BooleanValue = !booleanData.value; - break; - } + default: + case SetOperator.Assign: + (variable as IntegerVariable).Value = integerData.value; + break; + case SetOperator.Negate: + (variable as IntegerVariable).Value = -integerData.value; + break; + case SetOperator.Add: + (variable as IntegerVariable).Value += integerData.value; break; - case VariableType.Integer: - switch (setOperator) - { - default: - case SetOperator.Assign: - v.IntegerValue = integerData.value; - break; - case SetOperator.Negate: - v.IntegerValue = -integerData.value; - break; - case SetOperator.Add: - v.IntegerValue += integerData.value; - break; - case SetOperator.Subtract: - v.IntegerValue -= integerData.value; - break; - case SetOperator.Multiply: - v.IntegerValue *= integerData.value; - break; - case SetOperator.Divide: - v.IntegerValue /= integerData.value; - break; - } + case SetOperator.Subtract: + (variable as IntegerVariable).Value -= integerData.value; break; - case VariableType.Float: - switch (setOperator) - { - default: - case SetOperator.Assign: - v.FloatValue = floatData.value; - break; - case SetOperator.Negate: - v.FloatValue = -floatData.value; - break; - case SetOperator.Add: - v.FloatValue += floatData.value; - break; - case SetOperator.Subtract: - v.FloatValue -= floatData.value; - break; - case SetOperator.Multiply: - v.FloatValue *= floatData.value; - break; - case SetOperator.Divide: - v.FloatValue /= floatData.value; - break; - } + case SetOperator.Multiply: + (variable as IntegerVariable).Value *= integerData.value; break; - case VariableType.String: - switch (setOperator) - { - default: - case SetOperator.Assign: - v.StringValue = stringData.value; - break; - } + case SetOperator.Divide: + (variable as IntegerVariable).Value /= integerData.value; + break; + } + } + else if (variable.GetType() == typeof(FloatVariable)) + { + switch (setOperator) + { + default: + case SetOperator.Assign: + (variable as FloatVariable).Value = floatData.value; + break; + case SetOperator.Negate: + (variable as FloatVariable).Value = -floatData.value; + break; + case SetOperator.Add: + (variable as FloatVariable).Value += floatData.value; + break; + case SetOperator.Subtract: + (variable as FloatVariable).Value -= floatData.value; + break; + case SetOperator.Multiply: + (variable as FloatVariable).Value *= floatData.value; + break; + case SetOperator.Divide: + (variable as FloatVariable).Value /= floatData.value; + break; + } + } + else if (variable.GetType() == typeof(StringVariable)) + { + switch (setOperator) + { + default: + case SetOperator.Assign: + (variable as StringVariable).Value = stringData.value; break; } } diff --git a/Assets/Fungus/VisualScripting/StringVariable.cs b/Assets/Fungus/VisualScripting/StringVariable.cs new file mode 100644 index 00000000..a6395bee --- /dev/null +++ b/Assets/Fungus/VisualScripting/StringVariable.cs @@ -0,0 +1,18 @@ +using UnityEngine; +using System.Collections; + +namespace Fungus.Script +{ + + public class StringVariable : FungusVariable + { + string stringValue; + + public string Value + { + get { return (scope == VariableScope.Local) ? stringValue : Variables.GetString(key); } + set { if (scope == VariableScope.Local) { stringValue = value; } else { Variables.SetString(key, value); } } + } + } + +} \ No newline at end of file diff --git a/Assets/Fungus/VisualScripting/StringVariable.cs.meta b/Assets/Fungus/VisualScripting/StringVariable.cs.meta new file mode 100644 index 00000000..5f2e5795 --- /dev/null +++ b/Assets/Fungus/VisualScripting/StringVariable.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 4580f28dd8581476b810b38eea2f1316 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Assets/Fungus/VisualScripting/Variable.cs b/Assets/Fungus/VisualScripting/Variable.cs index 6c0336d8..5da439ae 100644 --- a/Assets/Fungus/VisualScripting/Variable.cs +++ b/Assets/Fungus/VisualScripting/Variable.cs @@ -4,7 +4,12 @@ using System.Collections; namespace Fungus.Script { - + public class FungusVariable : MonoBehaviour + { + public VariableScope scope; + public string key; + } + public enum VariableType { Boolean, @@ -18,64 +23,7 @@ namespace Fungus.Script Local, Global }; - - [Serializable] - public class Variable - { - public string key; - public VariableType type; - public VariableScope scope; - - bool booleanValue; - int integerValue; - float floatValue; - string stringValue; - - public bool BooleanValue - { - get { return (scope == VariableScope.Local) ? booleanValue : Variables.GetBoolean(key); } - set { if (scope == VariableScope.Local) { booleanValue = value; } else { Variables.SetBoolean(key, value); } } - } - - public int IntegerValue - { - get { return (scope == VariableScope.Local) ? integerValue : Variables.GetInteger(key); } - set { if (scope == VariableScope.Local) { integerValue = value; } else { Variables.SetInteger(key, value); } } - } - - public float FloatValue - { - get { return (scope == VariableScope.Local) ? floatValue : Variables.GetFloat(key); } - set { if (scope == VariableScope.Local) { floatValue = value; } else { Variables.SetFloat(key, value); } } - } - - public string StringValue - { - get { return (scope == VariableScope.Local) ? stringValue : Variables.GetString(key); } - set { if (scope == VariableScope.Local) { stringValue = value; } else { Variables.SetString(key, value); } } - } - - public bool IsSameType(Variable other) - { - return (this.type == other.type); - } - - public bool Assign(Variable other) - { - if (!IsSameType(other)) - { - return false; - } - - booleanValue = other.booleanValue; - integerValue = other.integerValue; - floatValue = other.floatValue; - stringValue = other.stringValue; - - return true; - } - } - + [Serializable] public class VariableData { diff --git a/Assets/Shuttle/ShuttleGame.unity b/Assets/Shuttle/ShuttleGame.unity index 428debebad532dc0b5c333a546c9b8c088f87269..080066c1efc1e57c2a2b5f06bd10a97a32f1e982 100644 GIT binary patch delta 2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