You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
149 lines
3.2 KiB
149 lines
3.2 KiB
10 years ago
|
using UnityEngine;
|
||
10 years ago
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
|
||
10 years ago
|
namespace Fungus.Script
|
||
10 years ago
|
{
|
||
|
|
||
|
public enum CompareOperator
|
||
|
{
|
||
|
Equals, // ==
|
||
|
NotEquals, // !=
|
||
|
LessThan, // <
|
||
|
GreaterThan, // >
|
||
|
LessThanOrEquals, // <=
|
||
|
GreaterThanOrEquals // >=
|
||
|
}
|
||
|
|
||
10 years ago
|
public class Compare : FungusCommand
|
||
10 years ago
|
{
|
||
|
public string variableKey;
|
||
|
|
||
|
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()
|
||
|
{
|
||
10 years ago
|
Variable v = parentFungusScript.GetVariable(variableKey);
|
||
10 years ago
|
|
||
|
bool condition = false;
|
||
|
|
||
|
switch (v.type)
|
||
|
{
|
||
|
case VariableType.Boolean:
|
||
|
switch (compareOperator)
|
||
|
{
|
||
|
case CompareOperator.Equals:
|
||
|
condition = (v.booleanValue == booleanData.value);
|
||
|
break;
|
||
|
case CompareOperator.NotEquals:
|
||
|
default:
|
||
|
condition = (v.booleanValue != booleanData.value);
|
||
|
break;
|
||
|
}
|
||
|
break;
|
||
|
case VariableType.Integer:
|
||
|
switch (compareOperator)
|
||
|
{
|
||
|
case CompareOperator.Equals:
|
||
|
condition = (v.integerValue == integerData.value);
|
||
|
break;
|
||
|
case CompareOperator.NotEquals:
|
||
|
condition = (v.integerValue != integerData.value);
|
||
|
break;
|
||
|
case CompareOperator.LessThan:
|
||
|
condition = (v.integerValue < integerData.value);
|
||
|
break;
|
||
|
case CompareOperator.GreaterThan:
|
||
|
condition = (v.integerValue > integerData.value);
|
||
|
break;
|
||
|
case CompareOperator.LessThanOrEquals:
|
||
|
condition = (v.integerValue <= integerData.value);
|
||
|
break;
|
||
|
case CompareOperator.GreaterThanOrEquals:
|
||
|
condition = (v.integerValue >= integerData.value);
|
||
|
break;
|
||
|
}
|
||
|
break;
|
||
|
case VariableType.Float:
|
||
|
switch (compareOperator)
|
||
|
{
|
||
|
case CompareOperator.Equals:
|
||
|
condition = (v.floatValue == floatData.value);
|
||
|
break;
|
||
|
case CompareOperator.NotEquals:
|
||
|
condition = (v.floatValue != floatData.value);
|
||
|
break;
|
||
|
case CompareOperator.LessThan:
|
||
|
condition = (v.floatValue < floatData.value);
|
||
|
break;
|
||
|
case CompareOperator.GreaterThan:
|
||
|
condition = (v.floatValue > floatData.value);
|
||
|
break;
|
||
|
case CompareOperator.LessThanOrEquals:
|
||
|
condition = (v.floatValue <= floatData.value);
|
||
|
break;
|
||
|
case CompareOperator.GreaterThanOrEquals:
|
||
|
condition = (v.floatValue >= floatData.value);
|
||
|
break;
|
||
|
}
|
||
|
break;
|
||
|
case VariableType.String:
|
||
|
switch (compareOperator)
|
||
|
{
|
||
|
case CompareOperator.Equals:
|
||
|
condition = (v.stringValue == stringData.value);
|
||
|
break;
|
||
|
case CompareOperator.NotEquals:
|
||
|
default:
|
||
|
condition = (v.stringValue != stringData.value);
|
||
|
break;
|
||
|
}
|
||
|
break;
|
||
|
}
|
||
|
|
||
|
if (condition)
|
||
|
{
|
||
|
if (onTrueSequence != null)
|
||
|
{
|
||
|
ExecuteSequence(onTrueSequence);
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
if (onFalseSequence != null)
|
||
|
{
|
||
|
ExecuteSequence(onFalseSequence);
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
|
||
10 years ago
|
Continue();
|
||
10 years ago
|
}
|
||
|
|
||
|
public override void GetConnectedSequences(ref List<Sequence> connectedSequences)
|
||
|
{
|
||
|
if (onTrueSequence != null)
|
||
|
{
|
||
|
connectedSequences.Add(onTrueSequence);
|
||
|
}
|
||
|
if (onFalseSequence != null)
|
||
|
{
|
||
|
connectedSequences.Add(onFalseSequence);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|