超级爆改
This commit is contained in:
42
Assets/Scripts/CommandSystem/CommandGroup.cs
Normal file
42
Assets/Scripts/CommandSystem/CommandGroup.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Ichni.Editor.Commands
|
||||
{
|
||||
/// <summary>
|
||||
/// 复合命令(命令宏)。用于将多个子指令打包成一次操作,常用于控制台多行指令或者范围选择后的群组修改。
|
||||
/// </summary>
|
||||
public class CommandGroup : ICommand
|
||||
{
|
||||
private List<ICommand> commands = new List<ICommand>();
|
||||
|
||||
public void Add(ICommand cmd)
|
||||
{
|
||||
commands.Add(cmd);
|
||||
}
|
||||
|
||||
public void Execute()
|
||||
{
|
||||
foreach (var cmd in commands) cmd.Execute();
|
||||
}
|
||||
|
||||
public void Undo()
|
||||
{
|
||||
// 撤销必须严格倒序,防止依赖性问题(如先生成再修改,撤回时需先改回去再抹除生成)
|
||||
for (int i = commands.Count - 1; i >= 0; i--)
|
||||
{
|
||||
commands[i].Undo();
|
||||
}
|
||||
}
|
||||
|
||||
public void Redo()
|
||||
{
|
||||
foreach (var cmd in commands) cmd.Redo();
|
||||
}
|
||||
|
||||
public bool TryMerge(ICommand other)
|
||||
{
|
||||
// 复合指令目前暂不介入针对数值连贯修改的归并推演逻辑
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user