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,39 +6,18 @@ using System.Collections.Generic;
namespace Fungus.Script
{
[CustomEditor (typeof(Call))]
public class CallEditor : FungusCommandEditor
[CustomEditor (typeof(If))]
public class IfEditor : FungusCommandEditor
{
public override void DrawCommandGUI()
{
serializedObject.Update();
Call t = target as Call;
FungusScript sc = t.GetFungusScript();
if (sc == null)
{
return;
}
If t = target as If;
CallCondition callCondition = (CallCondition)EditorGUILayout.EnumPopup(new GUIContent("Call Condition", "Condition when call will occur"), t.callCondition);
if (callCondition != t.callCondition)
FungusScript fungusScript = t.GetFungusScript();
if (fungusScript == null)
{
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;
}
@ -49,7 +28,7 @@ namespace Fungus.Script
if (fungusVariable != t.variable)
{
Undo.RecordObject(t, "Select variable");
Undo.RecordObject(t, "Select Variable");
t.variable = fungusVariable;
}
@ -70,52 +49,54 @@ namespace Fungus.Script
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"),
(int)t.compareOperator,
operatorList.ToArray());
if (compareOperator != t.compareOperator)
{
Undo.RecordObject(t, "Select compare operator");
Undo.RecordObject(t, "Select Compare Operator");
t.compareOperator = compareOperator;
}
if (t.variable.GetType() == typeof(BooleanVariable))
{
EditorGUILayout.PropertyField(serializedObject.FindProperty("booleanData"));
EditorGUILayout.PropertyField(serializedObject.FindProperty("booleanValue"));
}
else if (t.variable.GetType() == typeof(IntegerVariable))
{
EditorGUILayout.PropertyField(serializedObject.FindProperty("integerData"));
EditorGUILayout.PropertyField(serializedObject.FindProperty("integerValue"));
}
else if (t.variable.GetType() == typeof(FloatVariable))
{
EditorGUILayout.PropertyField(serializedObject.FindProperty("floatData"));
EditorGUILayout.PropertyField(serializedObject.FindProperty("floatValue"));
}
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>"),
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>"),
t.GetFungusScript(),
t.onFalseSequence);
t.elseSequence);
if (onTrue != t.onTrueSequence)
if (thenSequence != t.thenSequence)
{
Undo.RecordObject(t, "Set On True Sequence");
t.onTrueSequence = onTrue;
Undo.RecordObject(t, "Set Then Sequence");
t.thenSequence = thenSequence;
}
if (onFalse != t.onFalseSequence)
if (elseSequence != t.elseSequence)
{
Undo.RecordObject(t, "Set On False Sequence");
t.onFalseSequence = onFalse;
Undo.RecordObject(t, "Set Else Sequence");
t.elseSequence = elseSequence;
}
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
{
public enum CallCondition
{
CallAlways,
CallIf
}
public enum CompareOperator
{
Equals, // ==
@ -20,38 +14,27 @@ namespace Fungus.Script
GreaterThanOrEquals // >=
}
[HelpText("Start running another sequence. Can use a variable comparision to decide which sequence to run.")]
public class Call : FungusCommand
[HelpText("Execute another sequence IF a condition is true. Sequences can be specified for both true (THEN) and false (ELSE) conditions.")]
public class If : FungusCommand
{
public CallCondition callCondition;
public Sequence targetSequence; // Only used for Always condition
public FungusVariable variable;
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()
{
if (callCondition == CallCondition.CallAlways &&
targetSequence != null)
{
ExecuteSequence(targetSequence);
return;
}
bool condition = false;
if (variable == null)
@ -63,7 +46,7 @@ namespace Fungus.Script
if (variable.GetType() == typeof(BooleanVariable))
{
bool lhs = (variable as BooleanVariable).Value;
bool rhs = booleanData.Value;
bool rhs = booleanValue.Value;
switch (compareOperator)
{
@ -79,7 +62,7 @@ namespace Fungus.Script
else if (variable.GetType() == typeof(IntegerVariable))
{
int lhs = (variable as IntegerVariable).Value;
int rhs = integerData.Value;
int rhs = integerValue.Value;
switch (compareOperator)
{
@ -106,7 +89,7 @@ namespace Fungus.Script
else if (variable.GetType() == typeof(FloatVariable))
{
float lhs = (variable as FloatVariable).Value;
float rhs = floatData.Value;
float rhs = floatValue.Value;
switch (compareOperator)
{
@ -133,7 +116,7 @@ namespace Fungus.Script
else if (variable.GetType() == typeof(StringVariable))
{
string lhs = (variable as StringVariable).Value;
string rhs = stringData.Value;
string rhs = stringValue.Value;
switch (compareOperator)
{
@ -149,17 +132,17 @@ namespace Fungus.Script
if (condition)
{
if (onTrueSequence != null)
if (thenSequence != null)
{
ExecuteSequence(onTrueSequence);
ExecuteSequence(thenSequence);
return;
}
}
else
{
if (onFalseSequence != null)
if (elseSequence != null)
{
ExecuteSequence(onFalseSequence);
ExecuteSequence(elseSequence);
return;
}
}
@ -169,63 +152,44 @@ namespace Fungus.Script
public override void GetConnectedSequences(ref List<Sequence> connectedSequences)
{
if (callCondition == CallCondition.CallAlways &&
targetSequence != null)
{
connectedSequences.Add(targetSequence);
return;
}
if (onTrueSequence != null)
if (thenSequence != null)
{
connectedSequences.Add(onTrueSequence);
connectedSequences.Add(thenSequence);
}
if (onFalseSequence != null)
if (elseSequence != null)
{
connectedSequences.Add(onFalseSequence);
connectedSequences.Add(elseSequence);
}
}
public override string GetSummary()
{
if (callCondition == CallCondition.CallAlways)
if (variable == null)
{
if (targetSequence == null)
{
return "No target sequence selected";
}
return "No variable selected";
}
return targetSequence.name;
string description = "IF " + variable.key + " THEN ";
if (thenSequence == null)
{
description += "<Continue>";
}
else
{
if (variable == null)
{
return "No variable selected";
}
string description = "If " + variable.key + " then ";
if (onTrueSequence == null)
{
description += "<Continue>";
}
else
{
description += onTrueSequence.name;
}
description += " else ";
if (onFalseSequence == null)
{
description += "<Continue>";
}
else
{
description += onFalseSequence.name;
}
return description;
description += thenSequence.name;
}
description += " ELSE ";
if (elseSequence == null)
{
description += "<Continue>";
}
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