This project demonstrates a movement system in Unity that utilizes the Command Pattern, allowing for executing, undoing, and redoing player movement commands.
- CommandManager.cs: Manages the execution, undo, and redo of commands.
- ICommand.cs: Interface for commands.
- MoveCommand.cs: Abstract class for movement commands.
- MoveUpCommand.cs: Command for moving the player up.
- MoveDownCommand.cs: Command for moving the player down.
- MoveLeftCommand.cs: Command for moving the player left.
- MoveRightCommand.cs: Command for moving the player right.
- Player.cs: Handles player movement and command execution.
Manages the execution, undo, and redo stacks for commands.
- ExecuteCommand(ICommand command): Executes a command and adds it to the history stack.
- Undo(): Undoes the last executed command.
- Redo(): Redoes the last undone command.
Defines the methods for commands.
- Execute(): Executes the command.
- Undo(): Undoes the command.
Abstract class for movement commands, implementing the ICommand interface.
- Execute(): Saves the player's current position and moves the player in the specified direction.
- Undo(): Moves the player back to the previous position.
Concrete implementations of MoveCommand
for moving the player in different directions.
- MoveUpCommand: Moves the player up.
- MoveDownCommand: Moves the player down.
- MoveLeftCommand: Moves the player left.
- MoveRightCommand: Moves the player right.
Handles player movement, input detection, and command execution.
- Move(Vector3 direction): Moves the player in the specified direction.
- MoveToPosition(Vector3 position): Moves the player to the specified position.
- IsMoving(): Returns whether the player is currently moving.