MOD!
This commit is contained in:
@@ -4,35 +4,45 @@ using System.Linq;
|
||||
using UniRx;
|
||||
using UnityEngine;
|
||||
|
||||
namespace SoulliesFramework.General
|
||||
namespace SLSFramework.General
|
||||
{
|
||||
public enum ExecutionMode { Sequential, Parallel }
|
||||
|
||||
public class CommandGroup : CommandBase
|
||||
{
|
||||
private readonly List<ICommand> commands = new List<ICommand>();
|
||||
private readonly ExecutionMode mode;
|
||||
public readonly List<CommandBase> commands = new List<CommandBase>();
|
||||
public readonly ExecutionMode mode;
|
||||
|
||||
public CommandGroup(ExecutionMode mode, params ICommand[] commands)
|
||||
public CommandGroup(ExecutionMode mode, params CommandBase[] commands)
|
||||
{
|
||||
this.mode = mode;
|
||||
this.commands.AddRange(commands);
|
||||
}
|
||||
|
||||
public CommandGroup AddCommand(ICommand command)
|
||||
public override CommandBase Clone()
|
||||
{
|
||||
CommandGroup newGroup = new CommandGroup(mode);
|
||||
foreach (var cmd in commands)
|
||||
{
|
||||
newGroup.AddCommand(cmd.Clone());
|
||||
}
|
||||
return newGroup;
|
||||
}
|
||||
|
||||
public CommandGroup AddCommand(CommandBase command)
|
||||
{
|
||||
commands.Add(command);
|
||||
return this;
|
||||
}
|
||||
|
||||
protected override IObservable<Unit> OnExecute(CommandContext context)
|
||||
protected override IObservable<Unit> OnExecute(CommandContext outerContext)
|
||||
{
|
||||
// --- 核心修正 ---
|
||||
// 我们不再直接调用 cmd.Execute(context)。
|
||||
// 而是创建一个“延迟执行”的 Observable 序列。
|
||||
// Defer 会将对 Execute 的调用推迟到 Concat/WhenAll 真正订阅它的时候。
|
||||
var lazyCommandObservables = commands.Select(cmd =>
|
||||
Observable.Defer(() => cmd.Execute(context))
|
||||
Observable.Defer(() => cmd.Execute(outerContext))
|
||||
);
|
||||
|
||||
IObservable<Unit> executionFlow;
|
||||
|
||||
Reference in New Issue
Block a user