76 lines
1.8 KiB
C#
Raw Normal View History

2025-09-08 14:51:28 +08:00
using System;
using System.Collections.Generic;
using ZXKFramework;
public class TaskSequence
{
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>п<EFBFBD>ʼ<EFBFBD>ص<EFBFBD>
public Action onStart;
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɻص<C9BB>
public Action onFinish;
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>
private List<TaskProcedure> taskList;
public TaskSequence(Action onStart,Action onFinish)
{
taskList = new List<TaskProcedure>();
this.onFinish = onFinish;
this.onStart = onStart;
}
public TaskSequence Add(float delayTime, Action<TaskProcedure> taskFunc)
{
TaskProcedure task = new();
task.onTaskFunc = (taskParam) =>
{
Game.Instance.IEnumeratorManager.Run(delayTime, () =>
{
taskFunc(task);
taskParam.onComplete?.Invoke();
});
};
taskList.Add(task);
return this;
}
public TaskSequence Run()
{
onStart?.Invoke();
for (int i = 0; i < taskList.Count - 1; i++)
{
int index = i;
int nextIndex = index + 1;
taskList[index].onComplete = () => taskList[nextIndex].onTaskFunc(taskList[nextIndex]);
}
if (taskList.Count > 0)
{
taskList[taskList.Count - 1].onComplete = onFinish;
taskList[0].onTaskFunc(taskList[0]);
}
return this;
}
public void Clear()
{
onStart = null;
onFinish = null;
foreach (TaskProcedure task in taskList)
{
task.Dispose();
}
taskList.Clear();
}
}
/// <summary>
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// </summary>
public class TaskProcedure
{
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
public Action<TaskProcedure> onTaskFunc;
//<2F>ò<EFBFBD><C3B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɻص<C9BB>
public Action onComplete;
public void Dispose()
{
onTaskFunc = null;
onComplete = null;
}
}