|
|
|
using UnityEngine;
|
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
namespace Fungus.Script
|
|
|
|
{
|
|
|
|
public enum JumpCondition
|
|
|
|
{
|
|
|
|
JumpAlways,
|
|
|
|
JumpOnCompare
|
|
|
|
}
|
|
|
|
|
|
|
|
public enum CompareOperator
|
|
|
|
{
|
|
|
|
Equals, // ==
|
|
|
|
NotEquals, // !=
|
|
|
|
LessThan, // <
|
|
|
|
GreaterThan, // >
|
|
|
|
LessThanOrEquals, // <=
|
|
|
|
GreaterThanOrEquals // >=
|
|
|
|
}
|
|
|
|
|
|
|
|
public class Jump : FungusCommand
|
|
|
|
{
|
|
|
|
public JumpCondition jumpCondition;
|
|
|
|
|
|
|
|
public Sequence targetSequence; // Only used for Always condition
|
|
|
|
|
|
|
|
public FungusVariable variable;
|
|
|
|
|
|
|
|
public CompareOperator compareOperator;
|
|
|
|
|
|
|
|
public BooleanData booleanData;
|
|
|
|
|
|
|
|
public IntegerData integerData;
|
|
|
|
|
|
|
|
public FloatData floatData;
|
|
|
|
|
|
|
|
public StringData stringData;
|
|
|
|
|
|
|
|
public Sequence onTrueSequence;
|
|
|
|
|
|
|
|
public Sequence onFalseSequence;
|
|
|
|
|
|
|
|
public override void OnEnter()
|
|
|
|
{
|
|
|
|
if (jumpCondition == JumpCondition.JumpAlways &&
|
|
|
|
targetSequence != null)
|
|
|
|
{
|
|
|
|
ExecuteSequence(targetSequence);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool condition = false;
|
|
|
|
|
|
|
|
if (variable == null)
|
|
|
|
{
|
|
|
|
Continue();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (variable.GetType() == typeof(BooleanVariable))
|
|
|
|
{
|
|
|
|
bool lhs = (variable as BooleanVariable).Value;
|
|
|
|
bool rhs = booleanData.Value;
|
|
|
|
|
|
|
|
switch (compareOperator)
|
|
|
|
{
|
|
|
|
case CompareOperator.Equals:
|
|
|
|
condition = lhs == rhs;
|
|
|
|
break;
|
|
|
|
case CompareOperator.NotEquals:
|
|
|
|
default:
|
|
|
|
condition = lhs != rhs;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (variable.GetType() == typeof(IntegerVariable))
|
|
|
|
{
|
|
|
|
int lhs = (variable as IntegerVariable).Value;
|
|
|
|
int rhs = integerData.Value;
|
|
|
|
|
|
|
|
switch (compareOperator)
|
|
|
|
{
|
|
|
|
case CompareOperator.Equals:
|
|
|
|
condition = lhs == rhs;
|
|
|
|
break;
|
|
|
|
case CompareOperator.NotEquals:
|
|
|
|
condition = lhs != rhs;
|
|
|
|
break;
|
|
|
|
case CompareOperator.LessThan:
|
|
|
|
condition = lhs < rhs;
|
|
|
|
break;
|
|
|
|
case CompareOperator.GreaterThan:
|
|
|
|
condition = lhs > rhs;
|
|
|
|
break;
|
|
|
|
case CompareOperator.LessThanOrEquals:
|
|
|
|
condition = lhs <= rhs;
|
|
|
|
break;
|
|
|
|
case CompareOperator.GreaterThanOrEquals:
|
|
|
|
condition = lhs >= rhs;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (variable.GetType() == typeof(FloatVariable))
|
|
|
|
{
|
|
|
|
float lhs = (variable as FloatVariable).Value;
|
|
|
|
float rhs = floatData.Value;
|
|
|
|
|
|
|
|
switch (compareOperator)
|
|
|
|
{
|
|
|
|
case CompareOperator.Equals:
|
|
|
|
condition = lhs == rhs;
|
|
|
|
break;
|
|
|
|
case CompareOperator.NotEquals:
|
|
|
|
condition = lhs != rhs;
|
|
|
|
break;
|
|
|
|
case CompareOperator.LessThan:
|
|
|
|
condition = lhs < rhs;
|
|
|
|
break;
|
|
|
|
case CompareOperator.GreaterThan:
|
|
|
|
condition = lhs > rhs;
|
|
|
|
break;
|
|
|
|
case CompareOperator.LessThanOrEquals:
|
|
|
|
condition = lhs <= rhs;
|
|
|
|
break;
|
|
|
|
case CompareOperator.GreaterThanOrEquals:
|
|
|
|
condition = lhs >= rhs;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (variable.GetType() == typeof(StringVariable))
|
|
|
|
{
|
|
|
|
string lhs = (variable as StringVariable).Value;
|
|
|
|
string rhs = stringData.Value;
|
|
|
|
|
|
|
|
switch (compareOperator)
|
|
|
|
{
|
|
|
|
case CompareOperator.Equals:
|
|
|
|
condition = lhs == rhs;
|
|
|
|
break;
|
|
|
|
case CompareOperator.NotEquals:
|
|
|
|
default:
|
|
|
|
condition = lhs != rhs;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (condition)
|
|
|
|
{
|
|
|
|
if (onTrueSequence != null)
|
|
|
|
{
|
|
|
|
ExecuteSequence(onTrueSequence);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (onFalseSequence != null)
|
|
|
|
{
|
|
|
|
ExecuteSequence(onFalseSequence);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Continue();
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void GetConnectedSequences(ref List<Sequence> connectedSequences)
|
|
|
|
{
|
|
|
|
if (jumpCondition == JumpCondition.JumpAlways &&
|
|
|
|
targetSequence != null)
|
|
|
|
{
|
|
|
|
connectedSequences.Add(targetSequence);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (onTrueSequence != null)
|
|
|
|
{
|
|
|
|
connectedSequences.Add(onTrueSequence);
|
|
|
|
}
|
|
|
|
if (onFalseSequence != null)
|
|
|
|
{
|
|
|
|
connectedSequences.Add(onFalseSequence);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public override string GetCommandName()
|
|
|
|
{
|
|
|
|
if (jumpCondition == JumpCondition.JumpAlways)
|
|
|
|
{
|
|
|
|
return GetType().Name;
|
|
|
|
}
|
|
|
|
|
|
|
|
return GetType().Name + "?";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|