/// <summary> /// Moves an existing command from script to other place. /// Calls Removed and Inserted command events. /// </summary> public void MoveCommandBefore(Command source, Command before) { Debug.Assert(Commands.GetAllNodes().Select(n => n.value).Contains(source), "Source Command should exist on script"); Debug.Assert(Commands.GetAllNodes().Select(n => n.value).Contains(before), "Destination Command should exist on script"); var oldIndex = GetIndex(source); var sourceParentCommand = Commands.GetNodeFromValue(source).parent.value; var destParentCommand = Commands.GetNodeFromValue(before).parent.value; Commands.MoveBefore(source, before); CommandRemovedFromScript?.Invoke(this, sourceParentCommand, oldIndex); CommandInsertedInScript?.Invoke(this, destParentCommand, source, GetIndex(source)); m_IsDirty = true; CheckCommandGuidConsistency(); }
/// <summary> /// Removes node containing command. All child commands are also removed from script /// </summary> public void RemoveCommand(Command command) { Debug.Assert(Commands.GetAllNodes().Select(n => n.value).Contains(command), "Command should exist on script"); var oldIndex = GetIndex(command); var commandNode = Commands.GetNodeFromValue(command); var parentCommand = commandNode.parent.value; Commands.Remove(commandNode); foreach (var node in commandNode.GetAllNodes(true)) { m_CommandGuidMap.RemoveGuidFromMap(command); } CommandRemovedFromScript?.Invoke(this, parentCommand, oldIndex); m_IsDirty = true; CheckCommandGuidConsistency(); }
private void InvokeCommandRemovedFromScript(Script script, Command parentCommand, int index) { CommandRemovedFromScript?.Invoke(script, parentCommand, index); }