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");
T variable = fungusScript.gameObject.AddComponent<T>();
variable.key = fungusScript.GetUniqueVariableKey("");
fungusScript.variables.Add(variable);
T newVariable = ScriptableObject.CreateInstance<T>();
newVariable.key = fungusScript.GetUniqueVariableKey("");
fungusScript.variables.Add(newVariable);
}
}

9
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<GUIContent> operatorList = new List<GUIContent>();

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

@ -102,10 +102,9 @@ namespace Fungus
variableKeys.Add("<Value>");
variableObjects.Add(null);
Variable[] variables = fungusScript.GetComponents<Variable>();
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("<Value>");
variableObjects.Add(null);
Variable[] variables = fungusScript.GetComponents<Variable>();
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("<Value>");
variableObjects.Add(null);
Variable[] variables = fungusScript.GetComponents<Variable>();
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("<Value>");
variableObjects.Add(null);
Variable[] variables = fungusScript.GetComponents<Variable>();
int index = 0;
int selectedIndex = 0;
foreach (Variable v in variables)
foreach (Variable v in fungusScript.variables)
{
if (v.GetType() != typeof(StringVariable))
{

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

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

2
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 = "";

Loading…
Cancel
Save