12.10 进度 基本完成
This commit is contained in:
@@ -26,14 +26,34 @@ namespace SLSFramework.General
|
||||
public abstract class CommandBase
|
||||
{
|
||||
public bool insertAtFirst = false;
|
||||
|
||||
public float delayBeforeExecute = 0f;
|
||||
public CommandContext selfContext;
|
||||
|
||||
protected readonly Subject<Unit> forceCompleteSubject = new Subject<Unit>();
|
||||
|
||||
public void ForceComplete() => forceCompleteSubject.OnNext(Unit.Default);
|
||||
|
||||
// 子类可以重写这个方法来添加延迟逻辑
|
||||
protected virtual IObservable<Unit> OnExecute(CommandContext outerContext)
|
||||
{
|
||||
if (delayBeforeExecute > 0)
|
||||
{
|
||||
return Observable.Timer(TimeSpan.FromSeconds(delayBeforeExecute))
|
||||
.AsUnitObservable()
|
||||
.SelectMany(_ => CoreExecute(outerContext));
|
||||
}
|
||||
else
|
||||
{
|
||||
return CoreExecute(outerContext);
|
||||
}
|
||||
}
|
||||
|
||||
// 子类必须实现这个方法,定义指令的核心行为
|
||||
protected abstract IObservable<Unit> OnExecute(CommandContext outerContext);
|
||||
protected virtual IObservable<Unit> CoreExecute(CommandContext outerContext)
|
||||
{
|
||||
return Observable.Return(Unit.Default);
|
||||
}
|
||||
|
||||
protected virtual Func<CommandContext, bool> InnerCondition => (ctx) => true; // 默认条件为总是 true
|
||||
|
||||
@@ -55,6 +75,12 @@ namespace SLSFramework.General
|
||||
return clone;
|
||||
}
|
||||
|
||||
public virtual CommandBase SetDelay(float delay)
|
||||
{
|
||||
delayBeforeExecute = delay;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Execute 的公共入口。
|
||||
/// 它封装了条件判断、等待、或舍弃的复杂逻辑。
|
||||
|
||||
Reference in New Issue
Block a user