71 lines
1.8 KiB
C#
71 lines
1.8 KiB
C#
using System;
|
|
|
|
namespace AibisDream.Kit
|
|
{
|
|
public class Condition : IAction
|
|
{
|
|
private Func<bool> _condition;
|
|
|
|
private static readonly SimpleObjectPool<Condition> SimpleObjectPool = new(() => new Condition(), null, 10);
|
|
|
|
private Condition()
|
|
{
|
|
}
|
|
|
|
public static Condition Allocate(Func<bool> condition)
|
|
{
|
|
var conditionAction = SimpleObjectPool.Allocate();
|
|
conditionAction.ActionID = ActionKit.IDGenerator++;
|
|
conditionAction.IsFinalized = false;
|
|
conditionAction.Reset();
|
|
conditionAction._condition = condition;
|
|
return conditionAction;
|
|
}
|
|
|
|
public bool Paused { get; set; }
|
|
public bool IsFinalized { get; set; }
|
|
public ulong ActionID { get; set; }
|
|
public ActionStatus Status { get; set; }
|
|
|
|
public void OnStart()
|
|
{
|
|
}
|
|
|
|
public void OnExecute(float dt)
|
|
{
|
|
if (_condition.Invoke())
|
|
{
|
|
this.Finish();
|
|
}
|
|
}
|
|
|
|
public void OnFinish()
|
|
{
|
|
}
|
|
|
|
public void Deinit()
|
|
{
|
|
if (!IsFinalized)
|
|
{
|
|
IsFinalized = true;
|
|
_condition = null;
|
|
ActionKitMonoBehaviourEvents.AddCallback(
|
|
new ActionQueueRecycleCallback<Condition>(SimpleObjectPool, this));
|
|
}
|
|
}
|
|
|
|
public void Reset()
|
|
{
|
|
Paused = false;
|
|
Status = ActionStatus.NotStart;
|
|
}
|
|
}
|
|
|
|
public static class ConditionExtension
|
|
{
|
|
public static ISequence Condition(this ISequence self, Func<bool> condition)
|
|
{
|
|
return self.Append(Kit.Condition.Allocate(condition));
|
|
}
|
|
}
|
|
} |