您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
53 行
1.4 KiB
53 行
1.4 KiB
using NaughtyAttributes;
|
|
using System;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
|
|
namespace GameplayIngredients.Logic
|
|
{
|
|
public abstract class ConditionalLogic : LogicBase
|
|
{
|
|
[ReorderableList]
|
|
public Callable[] OnConditionValid;
|
|
|
|
[ReorderableList]
|
|
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
|
|
}
|
|
|
|
}
|
|
|
|
}
|