39 lines
1.4 KiB
C#
39 lines
1.4 KiB
C#
// 文件位置: TH1_Presentation/Sequencer/Task/ActionSequencerTask.cs
|
||
using System;
|
||
using Logic.CrashSight;
|
||
|
||
namespace TH1_Presentation.Sequencer.Task
|
||
{
|
||
// 轻量任务:执行一段 Action 后立刻完成。用于把"逻辑层产生的视觉刷新"按 PresentationManager 队列时序串行播放。
|
||
// 队列空闲时,PresentationManager.TryProcessNext 会立即同步 Execute,行为等价于直接调用 lambda;
|
||
// 队列有内容时(如 Explorer/Attack 动画正在播),会等队列消化完才执行,避免视觉"提前刷新"。
|
||
public class ActionSequencerTask : ISequencerTask
|
||
{
|
||
private readonly Action _action;
|
||
private readonly string _desc;
|
||
private Action _onCompleteCallback;
|
||
|
||
public ActionSequencerTask(Action action, string desc = "ActionSequencerTask")
|
||
{
|
||
_action = action;
|
||
_desc = string.IsNullOrEmpty(desc) ? "ActionSequencerTask" : desc;
|
||
}
|
||
|
||
public string GetDescString() => _desc;
|
||
|
||
public void Execute(Action onComplete)
|
||
{
|
||
_onCompleteCallback = onComplete;
|
||
try
|
||
{
|
||
_action?.Invoke();
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
LogSystem.LogError($"ActionSequencerTask[{_desc}] Exception: {e}");
|
||
}
|
||
_onCompleteCallback?.Invoke();
|
||
}
|
||
}
|
||
}
|