Browse Source

Pick variable or constant value

master
chrisgregan 10 years ago
parent
commit
239b9e7416
  1. 8
      Assets/Fungus/Editor/FungusScript/AddOptionEditor.cs
  2. 38
      Assets/Fungus/Editor/FungusScript/FungusVariableEditor.cs
  3. 94
      Assets/Fungus/Editor/FungusScript/JumpEditor.cs
  4. 8
      Assets/Fungus/Editor/FungusScript/SayEditor.cs
  5. 38
      Assets/Fungus/Editor/FungusScript/SequenceEditor.cs
  6. 85
      Assets/Fungus/Editor/FungusScript/SetEditor.cs
  7. 54
      Assets/Fungus/VisualScripting/Jump.cs
  8. 54
      Assets/Fungus/VisualScripting/Set.cs
  9. 35
      Assets/Fungus/VisualScripting/Variable.cs
  10. 8
      Assets/Fungus/VisualScripting/Variable.cs.meta

8
Assets/Fungus/Editor/FungusScript/AddOptionEditor.cs

@ -25,10 +25,10 @@ namespace Fungus.Script
if (showCondition == AddOption.ShowCondition.BooleanIsFalse ||
showCondition == AddOption.ShowCondition.BooleanIsTrue)
{
booleanVariable = SequenceEditor.VariableField (new GUIContent ("Boolean Variable", "Boolean variable to test for condition"),
t.GetFungusScript (),
t.booleanVariable,
v => { return v.GetType() == typeof(BooleanVariable); }) as BooleanVariable;
booleanVariable = FungusVariableEditor.VariableField (new GUIContent ("Boolean Variable", "Boolean variable to test for condition"),
t.GetFungusScript (),
t.booleanVariable,
v => { return v.GetType() == typeof(BooleanVariable); }) as BooleanVariable;
}
if (EditorGUI.EndChangeCheck())

38
Assets/Fungus/Editor/FungusScript/FungusVariableEditor.cs

@ -1,6 +1,7 @@
using UnityEditor;
using UnityEditorInternal;
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
@ -26,6 +27,43 @@ namespace Fungus.Script
t.scope = scope;
}
}
static public FungusVariable VariableField(GUIContent label, FungusScript fungusScript, FungusVariable variable, Func<FungusVariable, bool> filter = null)
{
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;
int selectedIndex = 0;
foreach (FungusVariable v in variables)
{
if (filter != null)
{
if (!filter(v))
{
continue;
}
}
variableKeys.Add(v.key);
variableObjects.Add(v);
index++;
if (v == variable)
{
selectedIndex = index;
}
}
selectedIndex = EditorGUILayout.Popup(label.text, selectedIndex, variableKeys.ToArray());
return variableObjects[selectedIndex];
}
}
}

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

@ -37,10 +37,10 @@ namespace Fungus.Script
return;
}
FungusVariable fungusVariable = SequenceEditor.VariableField(new GUIContent("Compare Variable", "Variable to use in compare operation"),
t.GetFungusScript(),
t.variable,
null);
FungusVariable fungusVariable = FungusVariableEditor.VariableField(new GUIContent("Compare Variable", "Variable to use in compare operation"),
t.GetFungusScript(),
t.variable,
null);
if (fungusVariable != t.variable)
{
@ -75,47 +75,61 @@ namespace Fungus.Script
t.compareOperator = compareOperator;
}
bool booleanValue = t.booleanData.value;
int integerValue = t.integerData.value;
float floatValue = t.floatData.value;
string stringValue = t.stringData.value;
FungusVariable compareVariable = FungusVariableEditor.VariableField(new GUIContent("Compare Variable", "Variable to compare with"),
t.GetFungusScript(),
t.compareVariable,
v => v.GetType() == fungusVariable.GetType());
if (t.variable.GetType() == typeof(BooleanVariable))
if (compareVariable != t.compareVariable)
{
booleanValue = EditorGUILayout.Toggle(new GUIContent("Boolean Value", "The boolean value to set the variable with"), booleanValue);
}
else if (t.variable.GetType() == typeof(IntegerVariable))
{
integerValue = EditorGUILayout.IntField(new GUIContent("Integer Value", "The integer value to set the variable with"), integerValue);
}
else if (t.variable.GetType() == typeof(FloatVariable))
{
floatValue = EditorGUILayout.FloatField(new GUIContent("Float Value", "The float value to set the variable with"), floatValue);
}
else if (t.variable.GetType() == typeof(StringVariable))
{
stringValue = EditorGUILayout.TextField(new GUIContent("String Value", "The string value to set the variable with"), stringValue);
Undo.RecordObject(t, "Select Compare Variable");
t.compareVariable = compareVariable;
}
if (booleanValue != t.booleanData.value)
{
Undo.RecordObject(t, "Set boolean value");
t.booleanData.value = booleanValue;
}
else if (integerValue != t.integerData.value)
if (compareVariable == null)
{
Undo.RecordObject(t, "Set integer value");
t.integerData.value = integerValue;
}
else if (floatValue != t.floatData.value)
{
Undo.RecordObject(t, "Set float value");
t.floatData.value = floatValue;
}
else if (stringValue != t.stringData.value)
{
Undo.RecordObject(t, "Set string value");
t.stringData.value = stringValue;
bool booleanValue = t.booleanValue;
int integerValue = t.integerValue;
float floatValue = t.floatValue;
string stringValue = t.stringValue;
if (t.variable.GetType() == typeof(BooleanVariable))
{
booleanValue = EditorGUILayout.Toggle(new GUIContent("Boolean Value", "The boolean value to set the variable with"), booleanValue);
}
else if (t.variable.GetType() == typeof(IntegerVariable))
{
integerValue = EditorGUILayout.IntField(new GUIContent("Integer Value", "The integer value to set the variable with"), integerValue);
}
else if (t.variable.GetType() == typeof(FloatVariable))
{
floatValue = EditorGUILayout.FloatField(new GUIContent("Float Value", "The float value to set the variable with"), floatValue);
}
else if (t.variable.GetType() == typeof(StringVariable))
{
stringValue = EditorGUILayout.TextField(new GUIContent("String Value", "The string value to set the variable with"), stringValue);
}
if (booleanValue != t.booleanValue)
{
Undo.RecordObject(t, "Set boolean value");
t.booleanValue = booleanValue;
}
else if (integerValue != t.integerValue)
{
Undo.RecordObject(t, "Set integer value");
t.integerValue = integerValue;
}
else if (floatValue != t.floatValue)
{
Undo.RecordObject(t, "Set float value");
t.floatValue = floatValue;
}
else if (stringValue != t.stringValue)
{
Undo.RecordObject(t, "Set string value");
t.stringValue = stringValue;
}
}
Sequence onTrue = SequenceEditor.SequenceField(new GUIContent("On True Sequence", "Sequence to execute if comparision is true"),

8
Assets/Fungus/Editor/FungusScript/SayEditor.cs

@ -29,10 +29,10 @@ namespace Fungus.Script
if (showCondition == Say.ShowCondition.BooleanIsFalse ||
showCondition == Say.ShowCondition.BooleanIsTrue)
{
booleanVariable = SequenceEditor.VariableField (new GUIContent ("Boolean Variable", "Boolean variable to test for condition"),
t.GetFungusScript (),
t.booleanVariable,
v => { return v.GetType() == typeof(BooleanVariable); }) as BooleanVariable;
booleanVariable = FungusVariableEditor.VariableField (new GUIContent ("Boolean Variable", "Boolean variable to test for condition"),
t.GetFungusScript (),
t.booleanVariable,
v => { return v.GetType() == typeof(BooleanVariable); }) as BooleanVariable;
}
if (EditorGUI.EndChangeCheck())

38
Assets/Fungus/Editor/FungusScript/SequenceEditor.cs

@ -3,7 +3,6 @@ using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace Fungus.Script
{
@ -48,43 +47,6 @@ namespace Fungus.Script
return result;
}
static public FungusVariable VariableField(GUIContent label, FungusScript fungusScript, FungusVariable variable, Func<FungusVariable, bool> filter = null)
{
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;
int selectedIndex = 0;
foreach (FungusVariable v in variables)
{
if (filter != null)
{
if (!filter(v))
{
continue;
}
}
variableKeys.Add(v.key);
variableObjects.Add(v);
index++;
if (v == variable)
{
selectedIndex = index;
}
}
selectedIndex = EditorGUILayout.Popup(label.text, selectedIndex, variableKeys.ToArray());
return variableObjects[selectedIndex];
}
}
}

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

@ -19,9 +19,9 @@ namespace Fungus.Script
return;
}
FungusVariable variable = SequenceEditor.VariableField(new GUIContent("Variable", "Variable to set"),
fungusScript,
t.variable);
FungusVariable variable = FungusVariableEditor.VariableField(new GUIContent("Variable", "Variable to set"),
fungusScript,
t.variable);
if (variable != t.variable)
{
@ -119,48 +119,53 @@ namespace Fungus.Script
Undo.RecordObject(t, "Set Operator");
t.setOperator = setOperator;
}
bool booleanValue = t.booleanData.value;
int integerValue = t.integerData.value;
float floatValue = t.floatData.value;
string stringValue = t.stringData.value;
if (variable.GetType() == typeof(BooleanVariable))
{
booleanValue = EditorGUILayout.Toggle(new GUIContent("Boolean Value", "The boolean value to set the variable with"), booleanValue);
}
else if (variable.GetType() == typeof(IntegerVariable))
{
integerValue = EditorGUILayout.IntField(new GUIContent("Integer Value", "The integer value to set the variable with"), integerValue);
}
else if (variable.GetType() == typeof(FloatVariable))
{
floatValue = EditorGUILayout.FloatField(new GUIContent("Float Value", "The float value to set the variable with"), floatValue);
}
else if (variable.GetType() == typeof(StringVariable))
{
stringValue = EditorGUILayout.TextField(new GUIContent("String Value", "The string value to set the variable with"), stringValue);
}
FungusVariable setVariable = FungusVariableEditor.VariableField(new GUIContent("Other Variable", "The variable to read the assigned value from."),
t.GetFungusScript(),
t.setVariable,
v => v.GetType() == variable.GetType ());
if (booleanValue != t.booleanData.value)
{
Undo.RecordObject(t, "Set boolean value");
t.booleanData.value = booleanValue;
}
else if (integerValue != t.integerData.value)
if (setVariable != t.setVariable)
{
Undo.RecordObject(t, "Set integer value");
t.integerData.value = integerValue;
Undo.RecordObject(t, "Select Set Variable");
t.setVariable = setVariable;
}
else if (floatValue != t.floatData.value)
{
Undo.RecordObject(t, "Set float value");
t.floatData.value = floatValue;
}
else if (stringValue != t.stringData.value)
if (setVariable == null)
{
Undo.RecordObject(t, "Set string value");
t.stringData.value = stringValue;
EditorGUI.BeginChangeCheck();
bool booleanValue = t.booleanValue;
int integerValue = t.integerValue;
float floatValue = t.floatValue;
string stringValue = t.stringValue;
if (variable.GetType() == typeof(BooleanVariable))
{
booleanValue = EditorGUILayout.Toggle (new GUIContent("Boolean Value", "A constant boolean value to set the variable with"), booleanValue);
}
else if (variable.GetType() == typeof(IntegerVariable))
{
integerValue = EditorGUILayout.IntField(new GUIContent("Integer Value", "A constant integer value to set the variable with"), integerValue);
}
else if (variable.GetType() == typeof(FloatVariable))
{
floatValue = EditorGUILayout.FloatField(new GUIContent("Float Value", "A constant float value to set the variable with"), floatValue);
}
else if (variable.GetType() == typeof(StringVariable))
{
stringValue = EditorGUILayout.TextField(new GUIContent("String Value", "A constant string value to set the variable with"), stringValue);
}
if (EditorGUI.EndChangeCheck())
{
Undo.RecordObject(t, "Set Variable Data");
t.booleanValue = booleanValue;
t.integerValue = integerValue;
t.floatValue = floatValue;
t.stringValue = stringValue;
}
}
}
}

54
Assets/Fungus/VisualScripting/Jump.cs

@ -30,13 +30,15 @@ namespace Fungus.Script
public CompareOperator compareOperator;
public BooleanData booleanData;
public FungusVariable compareVariable;
public IntegerData integerData;
public bool booleanValue;
public FloatData floatData;
public int integerValue;
public StringData stringData;
public float floatValue;
public string stringValue;
public Sequence onTrueSequence;
@ -61,75 +63,87 @@ namespace Fungus.Script
if (variable.GetType() == typeof(BooleanVariable))
{
bool lhs = (variable as BooleanVariable).Value;
bool rhs = (compareVariable as BooleanVariable) == null ? booleanValue : (compareVariable as BooleanVariable).Value;
switch (compareOperator)
{
case CompareOperator.Equals:
condition = (variable as BooleanVariable).Value == booleanData.value;
condition = lhs == rhs;
break;
case CompareOperator.NotEquals:
default:
condition = (variable as BooleanVariable).Value != booleanData.value;
condition = lhs != rhs;
break;
}
}
else if (variable.GetType() == typeof(IntegerVariable))
{
int lhs = (variable as IntegerVariable).Value;
int rhs = (compareVariable as IntegerVariable) == null ? integerValue : (compareVariable as IntegerVariable).Value;
switch (compareOperator)
{
case CompareOperator.Equals:
condition = (variable as IntegerVariable).Value == integerData.value;
condition = lhs == rhs;
break;
case CompareOperator.NotEquals:
condition = (variable as IntegerVariable).Value != integerData.value;
condition = lhs != rhs;
break;
case CompareOperator.LessThan:
condition = (variable as IntegerVariable).Value < integerData.value;
condition = lhs < rhs;
break;
case CompareOperator.GreaterThan:
condition = (variable as IntegerVariable).Value > integerData.value;
condition = lhs > rhs;
break;
case CompareOperator.LessThanOrEquals:
condition = (variable as IntegerVariable).Value <= integerData.value;
condition = lhs <= rhs;
break;
case CompareOperator.GreaterThanOrEquals:
condition = (variable as IntegerVariable).Value >= integerData.value;
condition = lhs >= rhs;
break;
}
}
else if (variable.GetType() == typeof(FloatVariable))
{
float lhs = (variable as FloatVariable).Value;
float rhs = (compareVariable as FloatVariable) == null ? floatValue : (compareVariable as FloatVariable).Value;
switch (compareOperator)
{
case CompareOperator.Equals:
condition = (variable as FloatVariable).Value == floatData.value;
condition = lhs == rhs;
break;
case CompareOperator.NotEquals:
condition = (variable as FloatVariable).Value != floatData.value;
condition = lhs != rhs;
break;
case CompareOperator.LessThan:
condition = (variable as FloatVariable).Value < floatData.value;
condition = lhs < rhs;
break;
case CompareOperator.GreaterThan:
condition = (variable as FloatVariable).Value > floatData.value;
condition = lhs > rhs;
break;
case CompareOperator.LessThanOrEquals:
condition = (variable as FloatVariable).Value <= floatData.value;
condition = lhs <= rhs;
break;
case CompareOperator.GreaterThanOrEquals:
condition = (variable as FloatVariable).Value >= floatData.value;
condition = lhs >= rhs;
break;
}
}
else if (variable.GetType() == typeof(StringVariable))
{
string lhs = (variable as StringVariable).Value;
string rhs = (compareVariable as StringVariable) == null ? stringValue : (compareVariable as StringVariable).Value;
switch (compareOperator)
{
case CompareOperator.Equals:
condition = (variable as StringVariable).Value == stringData.value;
condition = lhs == rhs;
break;
case CompareOperator.NotEquals:
default:
condition = (variable as StringVariable).Value != stringData.value;
condition = lhs != rhs;
break;
}
}

54
Assets/Fungus/VisualScripting/Set.cs

@ -20,13 +20,15 @@ namespace Fungus.Script
public SetOperator setOperator;
public BooleanData booleanData;
public FungusVariable setVariable;
public IntegerData integerData;
public bool booleanValue;
public FloatData floatData;
public int integerValue;
public StringData stringData;
public float floatValue;
public string stringValue;
public override void OnEnter()
{
@ -38,74 +40,80 @@ namespace Fungus.Script
if (variable.GetType() == typeof(BooleanVariable))
{
BooleanVariable lhs = (variable as BooleanVariable);
bool rhs = (setVariable as BooleanVariable) == null ? booleanValue : (setVariable as BooleanVariable).Value;
switch (setOperator)
{
default:
case SetOperator.Assign:
(variable as BooleanVariable).Value = booleanData.value;
lhs.Value = rhs;
break;
case SetOperator.Negate:
(variable as BooleanVariable).Value = !booleanData.value;
lhs.Value = !rhs;
break;
}
}
else if (variable.GetType() == typeof(IntegerVariable))
{
IntegerVariable lhs = (variable as IntegerVariable);
int rhs = (setVariable as IntegerVariable) == null ? integerValue : (setVariable as IntegerVariable).Value;
switch (setOperator)
{
default:
case SetOperator.Assign:
(variable as IntegerVariable).Value = integerData.value;
break;
case SetOperator.Negate:
(variable as IntegerVariable).Value = -integerData.value;
lhs.Value = rhs;
break;
case SetOperator.Add:
(variable as IntegerVariable).Value += integerData.value;
lhs.Value += rhs;
break;
case SetOperator.Subtract:
(variable as IntegerVariable).Value -= integerData.value;
lhs.Value -= rhs;
break;
case SetOperator.Multiply:
(variable as IntegerVariable).Value *= integerData.value;
lhs.Value *= rhs;
break;
case SetOperator.Divide:
(variable as IntegerVariable).Value /= integerData.value;
lhs.Value /= rhs;
break;
}
}
else if (variable.GetType() == typeof(FloatVariable))
{
FloatVariable lhs = (variable as FloatVariable);
float rhs = (setVariable as FloatVariable) == null ? floatValue : (setVariable as FloatVariable).Value;
switch (setOperator)
{
default:
case SetOperator.Assign:
(variable as FloatVariable).Value = floatData.value;
break;
case SetOperator.Negate:
(variable as FloatVariable).Value = -floatData.value;
lhs.Value = rhs;
break;
case SetOperator.Add:
(variable as FloatVariable).Value += floatData.value;
lhs.Value += rhs;
break;
case SetOperator.Subtract:
(variable as FloatVariable).Value -= floatData.value;
lhs.Value -= rhs;
break;
case SetOperator.Multiply:
(variable as FloatVariable).Value *= floatData.value;
lhs.Value *= rhs;
break;
case SetOperator.Divide:
(variable as FloatVariable).Value /= floatData.value;
lhs.Value /= rhs;
break;
}
}
else if (variable.GetType() == typeof(StringVariable))
{
StringVariable lhs = (variable as StringVariable);
string rhs = (setVariable as StringVariable) == null ? stringValue : (setVariable as StringVariable).Value;
switch (setOperator)
{
default:
case SetOperator.Assign:
(variable as StringVariable).Value = stringData.value;
lhs.Value = rhs;
break;
}
}

35
Assets/Fungus/VisualScripting/Variable.cs

@ -1,35 +0,0 @@
using UnityEngine;
using System;
using System.Collections;
namespace Fungus.Script
{
[Serializable]
public class VariableData
{
}
[Serializable]
public class BooleanData : VariableData
{
public bool value;
}
[Serializable]
public class IntegerData : VariableData
{
public int value;
}
[Serializable]
public class FloatData : VariableData
{
public float value;
}
[Serializable]
public class StringData : VariableData
{
public string value;
}
}

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

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 2f3853d313cd94fe184e3478cefc11f2
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
Loading…
Cancel
Save