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