HKMBFZ/Assets/SKFramework/Core/Action/ConcurrentActionChain.cs

55 lines
1.4 KiB
C#

using UnityEngine;
namespace SK.Framework
{
/// <summary>
/// 并行事件链
/// </summary>
public class ConcurrentActionChain : AbstractActionChain
{
public ConcurrentActionChain() : base() { }
public ConcurrentActionChain(MonoBehaviour executer) : base(executer) { }
protected override void OnInvoke()
{
if(stopWhen != null && stopWhen.Invoke())
{
isCompleted = true;
}
else if (!IsPaused)
{
for (int i = 0; i < invokeList.Count; i++)
{
if (invokeList[i].Invoke())
{
invokeList.RemoveAt(i);
i--;
}
}
isCompleted = invokeList.Count == 0;
}
if (isCompleted)
{
loops--;
if (loops != 0)
{
Reset();
}
else
{
isCompleted = true;
}
}
}
protected override void OnReset()
{
IsPaused = false;
for (int i = 0; i < cacheList.Count; i++)
{
cacheList[i].Reset();
invokeList.Add(cacheList[i]);
}
}
}
}