Building a controller adapter
Imagine you’re building an old-school top-down adventure game where players can run around an arena collecting items and jump over obstacles, using the traditional WASD and arrow keys. Nothing new in the mechanics department.
But now, suppose you wanted to spice things up and give players the ability to upgrade their movement controls, and you found the perfect mouse-follow and teleport script in a third-party library. Ideally, you’d like your existing game code to work with both the standard and mouse-follow movement controls, but you can’t modify the third-party script in any way. How would you make this scenario work?
Defining a target
The first step in our Adapter journey is creating a target interface, which holds all the responsibilities our adapter and adaptee classes are going to share. In the starter project, MovementController.cs
and TeleportController.cs
both have a way of moving the player, although the methods...