From 3fd20ed105d6f49391d1b96aa4333d7d9c10e8d5 Mon Sep 17 00:00:00 2001 From: chrisgregan Date: Wed, 10 Sep 2014 21:40:24 +0100 Subject: [PATCH] Variables are now ScriptableObjects instead of MonoBehaviors --- Assets/Example/Scenes/Example.unity | Bin 128372 -> 128364 bytes .../FungusScript/Editor/FungusScriptEditor.cs | 6 +++--- Assets/Fungus/FungusScript/Editor/IfEditor.cs | 9 +++++---- .../FungusScript/Editor/VariableEditor.cs | 12 ++++-------- .../FungusScript/Scripts/FungusScript.cs | 2 +- .../Fungus/FungusScript/Scripts/Variable.cs | 2 +- 6 files changed, 14 insertions(+), 17 deletions(-) diff --git a/Assets/Example/Scenes/Example.unity b/Assets/Example/Scenes/Example.unity index ba0a0795501997abb6542d4fa3b7ee2d8d63e3f5..e37a77544d69a8c681b116bc2460b7fe62c93613 100644 GIT binary patch delta 8078 zcmbW63tUxIzQ^|;5RQts&9m(>>ln+wNV`&}B$8p306(t45SAc>C6%-Yf z?p7BmB!f0Ng>>+shkM7zDX}QE;f@b*M)R02av<^16(=9_TYK*%d(Y=H_cNc{r}bHT zf6ssY|7-nUYpb`f1vOm@GD(y?MxvinDow+>yPG0jG|68?M7uYSF{C#G@HQ~qxIoWp+9q=*fj+aW*>oy(U({?qKce)9edlRP|g9{r^0>0^>BGo#)8 zSNyG;?6)G?z4j0!&BY-kTZ+W7LgedZ^W`T?^e5qmZ{F8Q-ahdF-BNU&{{}0s?*5}6 z-4=&CO7g~nK)Jttsp72WeGlDbu7mIt+)#O-g5)L-w|G8)?kFm_ahCBS1-s|gzDm@p z={+3euKMP#zntSAl$?YX64RZH2Rs+`1UUEv2fZuE5&A8$&tq`1# zcVXBLmexU%vcP=W7zfq@rdRkDSVBk1pzq?#ce><&P1WhU1m**a2fO>wsh;>UU|g^y zjRy?S#^0~XAw^)By2ZbMSvnavbC1h`6+o_4JKcS-sLrZq?r7`*SO%E>z%M%IKQI>o zPSzQD39J=NznQ^c_AZj-fZSb8Vb?$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~azzPn={mBsDYEhX^KbjyAO8Rmu|r`1 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 = "";