更新
This commit is contained in:
@@ -37,6 +37,19 @@ namespace SLSFramework.General
|
||||
return new ActionCommand(action).SetDelay(seconds);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建一条"等待外部信号"命令。
|
||||
/// 调用返回的 <paramref name="signal"/> Action 时,命令立即完成,队列继续执行。
|
||||
/// 典型用法:等待玩家点击按钮确认。
|
||||
/// </summary>
|
||||
/// <param name="signal">外部调用此委托以释放命令。</param>
|
||||
public static CommandBase WaitForSignal(out Action signal)
|
||||
{
|
||||
var tcs = new UniTaskCompletionSource();
|
||||
signal = () => tcs.TrySetResult();
|
||||
return new WaitForSignalCommand(tcs);
|
||||
}
|
||||
|
||||
// ── 组合工厂 ─────────────────────────────────────────────────────
|
||||
|
||||
/// <summary>创建一个顺序执行的命令组。</summary>
|
||||
@@ -135,5 +148,20 @@ namespace SLSFramework.General
|
||||
await asyncAction();
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class WaitForSignalCommand : CommandBase
|
||||
{
|
||||
private readonly UniTaskCompletionSource tcs;
|
||||
|
||||
public WaitForSignalCommand(UniTaskCompletionSource tcs)
|
||||
{
|
||||
this.tcs = tcs;
|
||||
}
|
||||
|
||||
protected override async UniTask ExecuteAsync(CommandContext outerContext)
|
||||
{
|
||||
await tcs.Task;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user