/// <summary> /// Performs a redo operation. /// </summary> private void Redo() { //added by me EventSystem.current.SetSelectedGameObject(null); // // Nothing to redo? if (_actionStack.Count == 0 || _actionStackPointer == _actionStack.Count - 1) { return; } if (RedoStart != null) { RedoStart(); } // Increment the stack pointer to the next command and redo it. ++_actionStackPointer; IUndoableAndRedoableAction actionToRedo = _actionStack[_actionStackPointer]; actionToRedo.Redo(); if (RedoEnd != null) { RedoEnd(); } }
/// <summary> /// Performs an undo operation. /// </summary> private void Undo() { //added by me EventSystem.current.SetSelectedGameObject(null); // // Nothing to undo? if (_actionStack.Count == 0 || _actionStackPointer < 0) { return; } if (UndoStart != null) { UndoStart(); } // Get the action pointed to by the stack pointer and undo it IUndoableAndRedoableAction actionToUndo = _actionStack[_actionStackPointer]; actionToUndo.Undo(); // Move the stack pointer backwards --_actionStackPointer; if (UndoEnd != null) { UndoEnd(); } }
/// <summary> /// Performs an undo operation. /// </summary> private void Undo() { // Nothing to undo? if (_actionStack.Count == 0 || _actionStackPointer < 0) { return; } if (UndoStart != null) { UndoStart(); } // Get the action pointed to by the stack pointer and undo it IUndoableAndRedoableAction actionToUndo = _actionStack[_actionStackPointer]; actionToUndo.Undo(); // Move the stack pointer backwards --_actionStackPointer; if (UndoEnd != null) { UndoEnd(); } }
/// <summary> /// Performs a redo operation. /// </summary> public void Redo() { // Nothing to redo? if (_actionStack.Count == 0 || _actionStackPointer == _actionStack.Count - 1) { return; } // Increment the stack pointer to the next command and redo it. ++_actionStackPointer; IUndoableAndRedoableAction actionToRedo = _actionStack[_actionStackPointer]; actionToRedo.Redo(); }
/// <summary> /// Performs an undo operation. /// </summary> public void Undo() { // Nothing to undo? if (_actionStack.Count == 0 || _actionStackPointer < 0) { return; } // Get the action pointed to by the stack pointer and undo it IUndoableAndRedoableAction actionToUndo = _actionStack[_actionStackPointer]; actionToUndo.Undo(); // Move the stack pointer backwards --_actionStackPointer; }
/// <summary> /// Registers an action with the undo/redo system. When an action is registered /// with the undo/redo system, it can be undone and redone as needed. /// </summary> public void RegisterAction(IUndoableAndRedoableAction action) { // Is this the first action registered? if (_actionStackPointer < 0) { // Just add the action to the stack and set the pointer to the first element _actionStack.Add(action); _actionStackPointer = 0; } else { // This is not the first action. Normally, we could just add the action on the top // of the stack, but we have to make sure that if the stack pointer does not point // at the top of the stack, all actions which follow after the stack pointer are // removed. This can happen when the user has performed a series of undo operations // because in that case, actions will not be popped from the stack. Only the stack // pointer will be moved downwards. This is what allows us to redo actions. However, // when a new action is registered, we will remove all actions which follow the one // referenced by the current stack pointer. if (_actionStackPointer < _actionStack.Count - 1) { // Calculate the index of the first action to be removed and the number of actions to remove int removeStartIndex = _actionStackPointer + 1; int removeCount = _actionStack.Count - removeStartIndex; // Remove the action range RemoveActionsRange(removeStartIndex, removeCount); } // Now we can add the new action on the top of the stack _actionStack.Add(action); // If the maximum number of actions has been exceeded, remove an action from the beginning of the stack if (_actionStack.Count > _actionLimit) { RemoveActionsRange(0, 1); } // Whenever a new action is registered, the stack pointer will be adjusted to point at the top of the stack _actionStackPointer = _actionStack.Count - 1; } }
/// <summary> /// Performs a redo operation. /// </summary> private void Redo() { // Nothing to redo? if (_actionStack.Count == 0 || _actionStackPointer == _actionStack.Count - 1) { return; } if (RedoStart != null) { RedoStart(); } // Increment the stack pointer to the next command and redo it. ++_actionStackPointer; IUndoableAndRedoableAction actionToRedo = _actionStack[_actionStackPointer]; actionToRedo.Redo(); if (RedoEnd != null) { RedoEnd(); } }