using UniRx; using System; using UnityEngine; namespace SoulliesFramework.General { /// /// 指令:等待指定秒数后,在控制台输出一条信息。 /// public class Cmd_WaitAndLog : CommandBase { private readonly float duration; private readonly string message; /// /// 构造函数 /// /// 需要等待的秒数。 /// 等待结束后需要输出的信息。 public Cmd_WaitAndLog(float duration, string message) { this.duration = duration; this.message = message; } protected override IObservable OnExecute(CommandContext context) { // 使用 Observable.Timer 来创建一个在指定时间后发出信号的流。 // Do 操作符用于在流的特定生命周期点执行副作用(例如打印日志)。 return Observable.Timer(TimeSpan.FromSeconds(duration)) .Do(_ => Debug.Log($"[Cmd_WaitAndLog] 等待 {duration} 秒后... 输出: '{message}'")) .AsUnitObservable(); } } }