您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
48 行
1.3 KiB
48 行
1.3 KiB
using System;
|
|
using UnityEngine;
|
|
|
|
namespace GameplayIngredients.Logic
|
|
{
|
|
public abstract class ConditionalLogic : LogicBase
|
|
{
|
|
public Callable[] OnConditionValid;
|
|
public Callable[] OnConditionInvalid;
|
|
|
|
public override void Execute(GameObject instigator = null)
|
|
{
|
|
if (GetCondition())
|
|
Callable.Call(OnConditionValid, instigator);
|
|
else
|
|
Callable.Call(OnConditionInvalid, instigator);
|
|
}
|
|
|
|
public abstract bool GetCondition();
|
|
|
|
protected static bool Compare<T>(T A, T B, Comparison c) where T : IComparable
|
|
{
|
|
int comp = A.CompareTo(B);
|
|
switch (c)
|
|
{
|
|
case Comparison.Equal: return comp == 0;
|
|
case Comparison.NotEqual: return comp != 0;
|
|
case Comparison.Greater: return comp > 0;
|
|
case Comparison.GreaterOrEqual: return comp >= 0;
|
|
case Comparison.Less: return comp < 0;
|
|
case Comparison.LessOrEqual: return comp <= 0;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public enum Comparison
|
|
{
|
|
Equal,
|
|
NotEqual,
|
|
Greater,
|
|
GreaterOrEqual,
|
|
Less,
|
|
LessOrEqual
|
|
}
|
|
|
|
}
|
|
|
|
}
|