/// <summary> /// Add a new command. /// </summary> public void newCommand(ICommand <T> command) { CommandElement <T> newCommandElement = new CommandElement <T> (); newCommandElement.id = commandCount; newCommandElement.command = command; commandList.Add(newCommandElement); commandCount += 1; }
/// <summary> /// Execute the newest command. /// </summary> public void executeNewestCommand() { for (int i = commandCount - 1; i >= 0; i--) { CommandElement <T> targetCommand = commandList.Find(x => x.id == i); if (targetCommand != null) { currentCommandID = i; targetCommand.command.execute(); } } }
/// <summary> /// Execute the command with specified id. /// </summary> public void executeCommand(int commandID) { currentCommandID = commandID; CommandElement <T> targetCommand = commandList.Find(x => x.id == commandID); if (targetCommand != null) { targetCommand.command.execute(); } else { throw new NullReferenceException("Command not found!"); } }