diff --git a/Assets/Example/Scenes/Example.unity b/Assets/Example/Scenes/Example.unity index ba0a0795..e37a7754 100644 Binary files a/Assets/Example/Scenes/Example.unity and b/Assets/Example/Scenes/Example.unity differ diff --git a/Assets/Fungus/FungusScript/Editor/FungusScriptEditor.cs b/Assets/Fungus/FungusScript/Editor/FungusScriptEditor.cs index 29650483..ea71ff8e 100644 --- a/Assets/Fungus/FungusScript/Editor/FungusScriptEditor.cs +++ b/Assets/Fungus/FungusScript/Editor/FungusScriptEditor.cs @@ -127,9 +127,9 @@ namespace Fungus } Undo.RecordObject(fungusScript, "Add Variable"); - T variable = fungusScript.gameObject.AddComponent(); - variable.key = fungusScript.GetUniqueVariableKey(""); - fungusScript.variables.Add(variable); + T newVariable = ScriptableObject.CreateInstance(); + newVariable.key = fungusScript.GetUniqueVariableKey(""); + fungusScript.variables.Add(newVariable); } } diff --git a/Assets/Fungus/FungusScript/Editor/IfEditor.cs b/Assets/Fungus/FungusScript/Editor/IfEditor.cs index d31f397e..aa560dc0 100644 --- a/Assets/Fungus/FungusScript/Editor/IfEditor.cs +++ b/Assets/Fungus/FungusScript/Editor/IfEditor.cs @@ -2,6 +2,7 @@ using UnityEditor; using UnityEngine; using System.Collections; using System.Collections.Generic; +using System.Reflection; namespace Fungus { @@ -39,9 +40,9 @@ namespace Fungus } VariableEditor.VariableField(variableProp, - new GUIContent("Variable", "Variable to use in operation"), - t.GetFungusScript(), - null); + new GUIContent("Variable", "Variable to use in operation"), + t.GetFungusScript(), + null); if (variableProp.objectReferenceValue == null) { @@ -49,7 +50,7 @@ namespace Fungus return; } - Variable selectedVariable = variableProp.objectReferenceValue as Variable; + Variable selectedVariable = (Variable)variableProp.objectReferenceValue; System.Type variableType = selectedVariable.GetType(); List operatorList = new List(); diff --git a/Assets/Fungus/FungusScript/Editor/VariableEditor.cs b/Assets/Fungus/FungusScript/Editor/VariableEditor.cs index cd1786d4..3c119acf 100644 --- a/Assets/Fungus/FungusScript/Editor/VariableEditor.cs +++ b/Assets/Fungus/FungusScript/Editor/VariableEditor.cs @@ -102,10 +102,9 @@ namespace Fungus variableKeys.Add(""); variableObjects.Add(null); - Variable[] variables = fungusScript.GetComponents(); int index = 0; int selectedIndex = 0; - foreach (Variable v in variables) + foreach (Variable v in fungusScript.variables) { if (v.GetType() != typeof(BooleanVariable)) { @@ -175,10 +174,9 @@ namespace Fungus variableKeys.Add(""); variableObjects.Add(null); - Variable[] variables = fungusScript.GetComponents(); int index = 0; int selectedIndex = 0; - foreach (Variable v in variables) + foreach (Variable v in fungusScript.variables) { if (v.GetType() != typeof(IntegerVariable)) { @@ -248,10 +246,9 @@ namespace Fungus variableKeys.Add(""); variableObjects.Add(null); - Variable[] variables = fungusScript.GetComponents(); int index = 0; int selectedIndex = 0; - foreach (Variable v in variables) + foreach (Variable v in fungusScript.variables) { if (v.GetType() != typeof(FloatVariable)) { @@ -321,10 +318,9 @@ namespace Fungus variableKeys.Add(""); variableObjects.Add(null); - Variable[] variables = fungusScript.GetComponents(); int index = 0; int selectedIndex = 0; - foreach (Variable v in variables) + foreach (Variable v in fungusScript.variables) { if (v.GetType() != typeof(StringVariable)) { diff --git a/Assets/Fungus/FungusScript/Scripts/FungusScript.cs b/Assets/Fungus/FungusScript/Scripts/FungusScript.cs index 079425c7..69b92662 100644 --- a/Assets/Fungus/FungusScript/Scripts/FungusScript.cs +++ b/Assets/Fungus/FungusScript/Scripts/FungusScript.cs @@ -110,7 +110,7 @@ namespace Fungus while (true) { bool collision = false; - foreach(Variable variable in GetComponents()) + foreach(Variable variable in variables) { if (variable == ignoreVariable || variable.key == null) diff --git a/Assets/Fungus/FungusScript/Scripts/Variable.cs b/Assets/Fungus/FungusScript/Scripts/Variable.cs index de5e70bf..b78f45b9 100644 --- a/Assets/Fungus/FungusScript/Scripts/Variable.cs +++ b/Assets/Fungus/FungusScript/Scripts/Variable.cs @@ -18,7 +18,7 @@ namespace Fungus Global } - public class Variable : MonoBehaviour + public class Variable : ScriptableObject { public VariableScope scope; public string key = "";