Browse Source

Variables are now ScriptableObjects instead of MonoBehaviors

master
chrisgregan 11 years ago
parent
commit
3fd20ed105
  1. BIN
      Assets/Example/Scenes/Example.unity
  2. 6
      Assets/Fungus/FungusScript/Editor/FungusScriptEditor.cs
  3. 9
      Assets/Fungus/FungusScript/Editor/IfEditor.cs
  4. 12
      Assets/Fungus/FungusScript/Editor/VariableEditor.cs
  5. 2
      Assets/Fungus/FungusScript/Scripts/FungusScript.cs
  6. 2
      Assets/Fungus/FungusScript/Scripts/Variable.cs

BIN
Assets/Example/Scenes/Example.unity

Binary file not shown.

6
Assets/Fungus/FungusScript/Editor/FungusScriptEditor.cs

@ -127,9 +127,9 @@ namespace Fungus
} }
Undo.RecordObject(fungusScript, "Add Variable"); Undo.RecordObject(fungusScript, "Add Variable");
T variable = fungusScript.gameObject.AddComponent<T>(); T newVariable = ScriptableObject.CreateInstance<T>();
variable.key = fungusScript.GetUniqueVariableKey(""); newVariable.key = fungusScript.GetUniqueVariableKey("");
fungusScript.variables.Add(variable); fungusScript.variables.Add(newVariable);
} }
} }

9
Assets/Fungus/FungusScript/Editor/IfEditor.cs

@ -2,6 +2,7 @@ using UnityEditor;
using UnityEngine; using UnityEngine;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Reflection;
namespace Fungus namespace Fungus
{ {
@ -39,9 +40,9 @@ namespace Fungus
} }
VariableEditor.VariableField(variableProp, VariableEditor.VariableField(variableProp,
new GUIContent("Variable", "Variable to use in operation"), new GUIContent("Variable", "Variable to use in operation"),
t.GetFungusScript(), t.GetFungusScript(),
null); null);
if (variableProp.objectReferenceValue == null) if (variableProp.objectReferenceValue == null)
{ {
@ -49,7 +50,7 @@ namespace Fungus
return; return;
} }
Variable selectedVariable = variableProp.objectReferenceValue as Variable; Variable selectedVariable = (Variable)variableProp.objectReferenceValue;
System.Type variableType = selectedVariable.GetType(); System.Type variableType = selectedVariable.GetType();
List<GUIContent> operatorList = new List<GUIContent>(); List<GUIContent> operatorList = new List<GUIContent>();

12
Assets/Fungus/FungusScript/Editor/VariableEditor.cs

@ -102,10 +102,9 @@ namespace Fungus
variableKeys.Add("<Value>"); variableKeys.Add("<Value>");
variableObjects.Add(null); variableObjects.Add(null);
Variable[] variables = fungusScript.GetComponents<Variable>();
int index = 0; int index = 0;
int selectedIndex = 0; int selectedIndex = 0;
foreach (Variable v in variables) foreach (Variable v in fungusScript.variables)
{ {
if (v.GetType() != typeof(BooleanVariable)) if (v.GetType() != typeof(BooleanVariable))
{ {
@ -175,10 +174,9 @@ namespace Fungus
variableKeys.Add("<Value>"); variableKeys.Add("<Value>");
variableObjects.Add(null); variableObjects.Add(null);
Variable[] variables = fungusScript.GetComponents<Variable>();
int index = 0; int index = 0;
int selectedIndex = 0; int selectedIndex = 0;
foreach (Variable v in variables) foreach (Variable v in fungusScript.variables)
{ {
if (v.GetType() != typeof(IntegerVariable)) if (v.GetType() != typeof(IntegerVariable))
{ {
@ -248,10 +246,9 @@ namespace Fungus
variableKeys.Add("<Value>"); variableKeys.Add("<Value>");
variableObjects.Add(null); variableObjects.Add(null);
Variable[] variables = fungusScript.GetComponents<Variable>();
int index = 0; int index = 0;
int selectedIndex = 0; int selectedIndex = 0;
foreach (Variable v in variables) foreach (Variable v in fungusScript.variables)
{ {
if (v.GetType() != typeof(FloatVariable)) if (v.GetType() != typeof(FloatVariable))
{ {
@ -321,10 +318,9 @@ namespace Fungus
variableKeys.Add("<Value>"); variableKeys.Add("<Value>");
variableObjects.Add(null); variableObjects.Add(null);
Variable[] variables = fungusScript.GetComponents<Variable>();
int index = 0; int index = 0;
int selectedIndex = 0; int selectedIndex = 0;
foreach (Variable v in variables) foreach (Variable v in fungusScript.variables)
{ {
if (v.GetType() != typeof(StringVariable)) if (v.GetType() != typeof(StringVariable))
{ {

2
Assets/Fungus/FungusScript/Scripts/FungusScript.cs

@ -110,7 +110,7 @@ namespace Fungus
while (true) while (true)
{ {
bool collision = false; bool collision = false;
foreach(Variable variable in GetComponents<Variable>()) foreach(Variable variable in variables)
{ {
if (variable == ignoreVariable || if (variable == ignoreVariable ||
variable.key == null) variable.key == null)

2
Assets/Fungus/FungusScript/Scripts/Variable.cs

@ -18,7 +18,7 @@ namespace Fungus
Global Global
} }
public class Variable : MonoBehaviour public class Variable : ScriptableObject
{ {
public VariableScope scope; public VariableScope scope;
public string key = ""; public string key = "";

Loading…
Cancel
Save