Browse Source

Variables are now components

master
chrisgregan 11 years ago
parent
commit
5b725896a3
  1. 12
      Assets/Fungus/Editor/FungusScript/AddOptionEditor.cs
  2. 23
      Assets/Fungus/Editor/FungusScript/FungusScriptEditor.cs
  3. 52
      Assets/Fungus/Editor/FungusScript/JumpEditor.cs
  4. 12
      Assets/Fungus/Editor/FungusScript/SayEditor.cs
  5. 37
      Assets/Fungus/Editor/FungusScript/SequenceEditor.cs
  6. 52
      Assets/Fungus/Editor/FungusScript/SetEditor.cs
  7. 48
      Assets/Fungus/Editor/FungusScript/VariablesWindow.cs
  8. 9
      Assets/Fungus/VisualScripting/AddOption.cs
  9. 18
      Assets/Fungus/VisualScripting/BooleanVariable.cs
  10. 8
      Assets/Fungus/VisualScripting/BooleanVariable.cs.meta
  11. 18
      Assets/Fungus/VisualScripting/FloatVariable.cs
  12. 8
      Assets/Fungus/VisualScripting/FloatVariable.cs.meta
  13. 14
      Assets/Fungus/VisualScripting/FungusScript.cs
  14. 18
      Assets/Fungus/VisualScripting/IntegerVariable.cs
  15. 8
      Assets/Fungus/VisualScripting/IntegerVariable.cs.meta
  16. 61
      Assets/Fungus/VisualScripting/Jump.cs
  17. 9
      Assets/Fungus/VisualScripting/Say.cs
  18. 61
      Assets/Fungus/VisualScripting/Set.cs
  19. 18
      Assets/Fungus/VisualScripting/StringVariable.cs
  20. 8
      Assets/Fungus/VisualScripting/StringVariable.cs.meta
  21. 62
      Assets/Fungus/VisualScripting/Variable.cs
  22. BIN
      Assets/Shuttle/ShuttleGame.unity

12
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"),
booleanVariable = SequenceEditor.VariableField (new GUIContent ("Boolean Variable", "Boolean variable to test for condition"),
t.GetFungusScript (),
t.booleanVariableKey,
ref type,
v => { return v.type == VariableType.Boolean; });
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;
}
}
}

23
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();
}
}

52
Assets/Fungus/Editor/FungusScript/JumpEditor.cs

@ -37,42 +37,27 @@ namespace Fungus.Script
return;
}
List<string> keys = new List<string>();
keys.Add("<None>");
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 == "<None>")
if (t.variable == null)
{
return;
}
VariableType variableType = sc.variables[newIndex - 1].type;
List<GUIContent> operatorList = new List<GUIContent>();
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)

12
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"),
booleanVariable = SequenceEditor.VariableField (new GUIContent ("Boolean Variable", "Boolean variable to test for condition"),
t.GetFungusScript (),
t.booleanVariableKey,
ref type,
v => { return v.type == VariableType.Boolean; });
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;
}
}

37
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<Variable, bool> filter = null)
static public FungusVariable VariableField(GUIContent label, FungusScript fungusScript, FungusVariable variable, Func<FungusVariable, bool> filter = null)
{
List<string> keys = new List<string>();
keys.Add("<None>");
List<string> variableKeys = new List<string>();
List<FungusVariable> variableObjects = new List<FungusVariable>();
variableKeys.Add("<None>");
variableObjects.Add(null);
FungusVariable[] variables = fungusScript.GetComponents<FungusVariable>();
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)
{
index = i + 1;
}
}
variableKeys.Add(v.key);
variableObjects.Add(v);
int newIndex = EditorGUILayout.Popup(label.text, index, keys.ToArray());
index++;
if (newIndex > 0)
if (v == variable)
{
variableType = fungusScript.variables[newIndex - 1].type;
selectedIndex = index;
}
}
selectedIndex = EditorGUILayout.Popup(label.text, selectedIndex, variableKeys.ToArray());
return keys[newIndex];
return variableObjects[selectedIndex];
}
}

52
Assets/Fungus/Editor/FungusScript/SetEditor.cs

@ -19,32 +19,29 @@ namespace Fungus.Script
return;
}
VariableType variableType = VariableType.Boolean;
string variableKey = SequenceEditor.VariableField(new GUIContent("Variable", "Variable to set"),
FungusVariable variable = SequenceEditor.VariableField(new GUIContent("Variable", "Variable to set"),
fungusScript,
t.variableKey,
ref variableType);
t.variable);
if (variableKey != t.variableKey)
if (variable != t.variable)
{
Undo.RecordObject(t, "Set Variable Key");
t.variableKey = variableKey;
t.variable = variable;
}
if (t.variableKey == "<None>")
if (t.variable == null)
{
return;
}
List<GUIContent> operatorsList = new List<GUIContent>();
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("-"));
@ -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)

48
Assets/Fungus/Editor/FungusScript/VariablesWindow.cs

@ -27,24 +27,25 @@ namespace Fungus.Script
}
// Warn about conflicting global variable types
Dictionary<string, VariableType> globalTypes = new Dictionary<string, VariableType>();
Dictionary<string, FungusVariable> globals = new Dictionary<string, FungusVariable>();
FungusScript[] fungusScripts = GameObject.FindObjectsOfType<FungusScript>();
foreach (FungusScript fs in fungusScripts)
{
foreach (Variable v in fs.variables)
FungusVariable[] variables = fs.GetComponents<FungusVariable>();
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<FungusVariable>();
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));

9
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;
}

18
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); } }
}
}
}

8
Assets/Fungus/VisualScripting/BooleanVariable.cs.meta

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 5d02d9822eec54c98afe95bb497211b3
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

18
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); } }
}
}
}

8
Assets/Fungus/VisualScripting/FloatVariable.cs.meta

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 705fa1ac97df74e3a84ff952ffd923f1
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

14
Assets/Fungus/VisualScripting/FungusScript.cs

@ -18,8 +18,6 @@ namespace Fungus.Script
[System.NonSerialized]
public Sequence activeSequence;
public List<Variable> variables = new List<Variable>();
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;
}
}
}

18
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); } }
}
}
}

8
Assets/Fungus/VisualScripting/IntegerVariable.cs.meta

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: afb91b566ceda411bad1e9d3c3243ecc
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

61
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)

9
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;
}

61
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.");
}
else
{
switch (v.type)
{
case VariableType.Boolean:
switch (setOperator)
{
default:
case SetOperator.Assign:
v.BooleanValue = booleanData.value;
(variable as BooleanVariable).Value = booleanData.value;
break;
case SetOperator.Negate:
v.BooleanValue = !booleanData.value;
(variable as BooleanVariable).Value = !booleanData.value;
break;
}
break;
case VariableType.Integer:
}
else if (variable.GetType() == typeof(IntegerVariable))
{
switch (setOperator)
{
default:
case SetOperator.Assign:
v.IntegerValue = integerData.value;
(variable as IntegerVariable).Value = integerData.value;
break;
case SetOperator.Negate:
v.IntegerValue = -integerData.value;
(variable as IntegerVariable).Value = -integerData.value;
break;
case SetOperator.Add:
v.IntegerValue += integerData.value;
(variable as IntegerVariable).Value += integerData.value;
break;
case SetOperator.Subtract:
v.IntegerValue -= integerData.value;
(variable as IntegerVariable).Value -= integerData.value;
break;
case SetOperator.Multiply:
v.IntegerValue *= integerData.value;
(variable as IntegerVariable).Value *= integerData.value;
break;
case SetOperator.Divide:
v.IntegerValue /= integerData.value;
(variable as IntegerVariable).Value /= integerData.value;
break;
}
break;
case VariableType.Float:
}
else if (variable.GetType() == typeof(FloatVariable))
{
switch (setOperator)
{
default:
case SetOperator.Assign:
v.FloatValue = floatData.value;
(variable as FloatVariable).Value = floatData.value;
break;
case SetOperator.Negate:
v.FloatValue = -floatData.value;
(variable as FloatVariable).Value = -floatData.value;
break;
case SetOperator.Add:
v.FloatValue += floatData.value;
(variable as FloatVariable).Value += floatData.value;
break;
case SetOperator.Subtract:
v.FloatValue -= floatData.value;
(variable as FloatVariable).Value -= floatData.value;
break;
case SetOperator.Multiply:
v.FloatValue *= floatData.value;
(variable as FloatVariable).Value *= floatData.value;
break;
case SetOperator.Divide:
v.FloatValue /= floatData.value;
(variable as FloatVariable).Value /= floatData.value;
break;
}
break;
case VariableType.String:
}
else if (variable.GetType() == typeof(StringVariable))
{
switch (setOperator)
{
default:
case SetOperator.Assign:
v.StringValue = stringData.value;
break;
}
(variable as StringVariable).Value = stringData.value;
break;
}
}

18
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); } }
}
}
}

8
Assets/Fungus/VisualScripting/StringVariable.cs.meta

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 4580f28dd8581476b810b38eea2f1316
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

62
Assets/Fungus/VisualScripting/Variable.cs

@ -4,6 +4,11 @@ using System.Collections;
namespace Fungus.Script
{
public class FungusVariable : MonoBehaviour
{
public VariableScope scope;
public string key;
}
public enum VariableType
{
@ -19,63 +24,6 @@ namespace Fungus.Script
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
{

BIN
Assets/Shuttle/ShuttleGame.unity

Binary file not shown.
Loading…
Cancel
Save