Browse Source

Split Call command into Call and If

master
chrisgregan 11 years ago
parent
commit
c0f1ed9d0e
  1. 67
      Assets/Fungus/Editor/FungusScript/IfEditor.cs
  2. 8
      Assets/Fungus/Editor/FungusScript/IfEditor.cs.meta
  3. 116
      Assets/Fungus/VisualScripting/If.cs
  4. 8
      Assets/Fungus/VisualScripting/If.cs.meta
  5. BIN
      Assets/Shuttle/ShuttleGame.unity

67
Assets/Fungus/Editor/FungusScript/CallEditor.cs → Assets/Fungus/Editor/FungusScript/IfEditor.cs

@ -6,42 +6,21 @@ using System.Collections.Generic;
namespace Fungus.Script namespace Fungus.Script
{ {
[CustomEditor (typeof(Call))] [CustomEditor (typeof(If))]
public class CallEditor : FungusCommandEditor public class IfEditor : FungusCommandEditor
{ {
public override void DrawCommandGUI() public override void DrawCommandGUI()
{ {
serializedObject.Update(); serializedObject.Update();
Call t = target as Call; If t = target as If;
FungusScript sc = t.GetFungusScript(); FungusScript fungusScript = t.GetFungusScript();
if (sc == null) if (fungusScript == null)
{ {
return; return;
} }
CallCondition callCondition = (CallCondition)EditorGUILayout.EnumPopup(new GUIContent("Call Condition", "Condition when call will occur"), t.callCondition);
if (callCondition != t.callCondition)
{
Undo.RecordObject(t, "Set Call Condition");
t.callCondition = callCondition;
}
if (t.callCondition == CallCondition.CallAlways)
{
Sequence targetSequence = SequenceEditor.SequenceField(new GUIContent("Target Sequence", "Sequence to call"),
new GUIContent("<Continue>"),
t.GetFungusScript(),
t.targetSequence);
if (targetSequence != t.targetSequence)
{
Undo.RecordObject(t, "Set Target Sequence");
t.targetSequence = targetSequence;
}
return;
}
FungusVariable fungusVariable = FungusVariableEditor.VariableField(new GUIContent("Variable", "Variable to use in operation"), FungusVariable fungusVariable = FungusVariableEditor.VariableField(new GUIContent("Variable", "Variable to use in operation"),
t.GetFungusScript(), t.GetFungusScript(),
t.variable, t.variable,
@ -49,7 +28,7 @@ namespace Fungus.Script
if (fungusVariable != t.variable) if (fungusVariable != t.variable)
{ {
Undo.RecordObject(t, "Select variable"); Undo.RecordObject(t, "Select Variable");
t.variable = fungusVariable; t.variable = fungusVariable;
} }
@ -70,52 +49,54 @@ namespace Fungus.Script
operatorList.Add(new GUIContent(">=")); operatorList.Add(new GUIContent(">="));
} }
CompareOperator compareOperator = (CompareOperator)EditorGUILayout.Popup(new GUIContent("Operator", CompareOperator compareOperator = (CompareOperator)EditorGUILayout.Popup(new GUIContent("Compare",
"The comparison operator to use when comparing values"), "The comparison operator to use when comparing values"),
(int)t.compareOperator, (int)t.compareOperator,
operatorList.ToArray()); operatorList.ToArray());
if (compareOperator != t.compareOperator) if (compareOperator != t.compareOperator)
{ {
Undo.RecordObject(t, "Select compare operator"); Undo.RecordObject(t, "Select Compare Operator");
t.compareOperator = compareOperator; t.compareOperator = compareOperator;
} }
if (t.variable.GetType() == typeof(BooleanVariable)) if (t.variable.GetType() == typeof(BooleanVariable))
{ {
EditorGUILayout.PropertyField(serializedObject.FindProperty("booleanData")); EditorGUILayout.PropertyField(serializedObject.FindProperty("booleanValue"));
} }
else if (t.variable.GetType() == typeof(IntegerVariable)) else if (t.variable.GetType() == typeof(IntegerVariable))
{ {
EditorGUILayout.PropertyField(serializedObject.FindProperty("integerData")); EditorGUILayout.PropertyField(serializedObject.FindProperty("integerValue"));
} }
else if (t.variable.GetType() == typeof(FloatVariable)) else if (t.variable.GetType() == typeof(FloatVariable))
{ {
EditorGUILayout.PropertyField(serializedObject.FindProperty("floatData")); EditorGUILayout.PropertyField(serializedObject.FindProperty("floatValue"));
} }
else if (t.variable.GetType() == typeof(StringVariable)) else if (t.variable.GetType() == typeof(StringVariable))
{ {
EditorGUILayout.PropertyField(serializedObject.FindProperty("stringData")); EditorGUILayout.PropertyField(serializedObject.FindProperty("stringValue"));
} }
Sequence onTrue = SequenceEditor.SequenceField(new GUIContent("On True Sequence", "Sequence to execute if comparision is true"), EditorGUILayout.Separator();
Sequence thenSequence = SequenceEditor.SequenceField(new GUIContent("Then", "Sequence to execute if comparision is true"),
new GUIContent("<Continue>"), new GUIContent("<Continue>"),
t.GetFungusScript(), t.GetFungusScript(),
t.onTrueSequence); t.thenSequence);
Sequence onFalse = SequenceEditor.SequenceField(new GUIContent("On False Sequence", "Sequence to execute if comparision is false"), Sequence elseSequence = SequenceEditor.SequenceField(new GUIContent("Else", "Sequence to execute if comparision is false"),
new GUIContent("<Continue>"), new GUIContent("<Continue>"),
t.GetFungusScript(), t.GetFungusScript(),
t.onFalseSequence); t.elseSequence);
if (onTrue != t.onTrueSequence) if (thenSequence != t.thenSequence)
{ {
Undo.RecordObject(t, "Set On True Sequence"); Undo.RecordObject(t, "Set Then Sequence");
t.onTrueSequence = onTrue; t.thenSequence = thenSequence;
} }
if (onFalse != t.onFalseSequence) if (elseSequence != t.elseSequence)
{ {
Undo.RecordObject(t, "Set On False Sequence"); Undo.RecordObject(t, "Set Else Sequence");
t.onFalseSequence = onFalse; t.elseSequence = elseSequence;
} }
serializedObject.ApplyModifiedProperties(); serializedObject.ApplyModifiedProperties();

8
Assets/Fungus/Editor/FungusScript/IfEditor.cs.meta

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

116
Assets/Fungus/VisualScripting/Call.cs → Assets/Fungus/VisualScripting/If.cs

@ -4,12 +4,6 @@ using System.Collections.Generic;
namespace Fungus.Script namespace Fungus.Script
{ {
public enum CallCondition
{
CallAlways,
CallIf
}
public enum CompareOperator public enum CompareOperator
{ {
Equals, // == Equals, // ==
@ -20,38 +14,27 @@ namespace Fungus.Script
GreaterThanOrEquals // >= GreaterThanOrEquals // >=
} }
[HelpText("Start running another sequence. Can use a variable comparision to decide which sequence to run.")] [HelpText("Execute another sequence IF a condition is true. Sequences can be specified for both true (THEN) and false (ELSE) conditions.")]
public class Call : FungusCommand public class If : FungusCommand
{ {
public CallCondition callCondition;
public Sequence targetSequence; // Only used for Always condition
public FungusVariable variable; public FungusVariable variable;
public CompareOperator compareOperator; public CompareOperator compareOperator;
public BooleanData booleanData; public BooleanData booleanValue;
public IntegerData integerData; public IntegerData integerValue;
public FloatData floatData; public FloatData floatValue;
public StringData stringData; public StringData stringValue;
public Sequence onTrueSequence; public Sequence thenSequence;
public Sequence onFalseSequence; public Sequence elseSequence;
public override void OnEnter() public override void OnEnter()
{ {
if (callCondition == CallCondition.CallAlways &&
targetSequence != null)
{
ExecuteSequence(targetSequence);
return;
}
bool condition = false; bool condition = false;
if (variable == null) if (variable == null)
@ -63,7 +46,7 @@ namespace Fungus.Script
if (variable.GetType() == typeof(BooleanVariable)) if (variable.GetType() == typeof(BooleanVariable))
{ {
bool lhs = (variable as BooleanVariable).Value; bool lhs = (variable as BooleanVariable).Value;
bool rhs = booleanData.Value; bool rhs = booleanValue.Value;
switch (compareOperator) switch (compareOperator)
{ {
@ -79,7 +62,7 @@ namespace Fungus.Script
else if (variable.GetType() == typeof(IntegerVariable)) else if (variable.GetType() == typeof(IntegerVariable))
{ {
int lhs = (variable as IntegerVariable).Value; int lhs = (variable as IntegerVariable).Value;
int rhs = integerData.Value; int rhs = integerValue.Value;
switch (compareOperator) switch (compareOperator)
{ {
@ -106,7 +89,7 @@ namespace Fungus.Script
else if (variable.GetType() == typeof(FloatVariable)) else if (variable.GetType() == typeof(FloatVariable))
{ {
float lhs = (variable as FloatVariable).Value; float lhs = (variable as FloatVariable).Value;
float rhs = floatData.Value; float rhs = floatValue.Value;
switch (compareOperator) switch (compareOperator)
{ {
@ -133,7 +116,7 @@ namespace Fungus.Script
else if (variable.GetType() == typeof(StringVariable)) else if (variable.GetType() == typeof(StringVariable))
{ {
string lhs = (variable as StringVariable).Value; string lhs = (variable as StringVariable).Value;
string rhs = stringData.Value; string rhs = stringValue.Value;
switch (compareOperator) switch (compareOperator)
{ {
@ -149,17 +132,17 @@ namespace Fungus.Script
if (condition) if (condition)
{ {
if (onTrueSequence != null) if (thenSequence != null)
{ {
ExecuteSequence(onTrueSequence); ExecuteSequence(thenSequence);
return; return;
} }
} }
else else
{ {
if (onFalseSequence != null) if (elseSequence != null)
{ {
ExecuteSequence(onFalseSequence); ExecuteSequence(elseSequence);
return; return;
} }
} }
@ -169,63 +152,44 @@ namespace Fungus.Script
public override void GetConnectedSequences(ref List<Sequence> connectedSequences) public override void GetConnectedSequences(ref List<Sequence> connectedSequences)
{ {
if (callCondition == CallCondition.CallAlways && if (thenSequence != null)
targetSequence != null)
{ {
connectedSequences.Add(targetSequence); connectedSequences.Add(thenSequence);
return;
} }
if (elseSequence != null)
if (onTrueSequence != null)
{
connectedSequences.Add(onTrueSequence);
}
if (onFalseSequence != null)
{ {
connectedSequences.Add(onFalseSequence); connectedSequences.Add(elseSequence);
} }
} }
public override string GetSummary() public override string GetSummary()
{ {
if (callCondition == CallCondition.CallAlways) if (variable == null)
{ {
if (targetSequence == null) return "No variable selected";
{ }
return "No target sequence selected";
}
return targetSequence.name; string description = "IF " + variable.key + " THEN ";
if (thenSequence == null)
{
description += "<Continue>";
} }
else else
{ {
if (variable == null) description += thenSequence.name;
{ }
return "No variable selected"; description += " ELSE ";
} if (elseSequence == null)
{
string description = "If " + variable.key + " then "; description += "<Continue>";
if (onTrueSequence == null)
{
description += "<Continue>";
}
else
{
description += onTrueSequence.name;
}
description += " else ";
if (onFalseSequence == null)
{
description += "<Continue>";
}
else
{
description += onFalseSequence.name;
}
return description;
} }
else
{
description += elseSequence.name;
}
return description;
} }
} }

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

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

BIN
Assets/Shuttle/ShuttleGame.unity

Binary file not shown.
Loading…
Cancel
Save