Book Image

Learning Design Patterns with Unity

By : Harrison Ferrone
Book Image

Learning Design Patterns with Unity

By: Harrison Ferrone

Overview of this book

Struggling to write maintainable and clean code for your Unity games? Look no further! Learning Design Patterns with Unity empowers you to harness the fullest potential of popular design patterns while building exciting Unity projects. Through hands-on game development, you'll master creational patterns like Prototype to efficiently spawn enemies and delve into behavioral patterns like Observer to create reactive game mechanics. As you progress, you'll also identify the negative impacts of bad architectural decisions and understand how to overcome them with simple but effective practices. By the end of this Unity 2023 book, the way you develop Unity games will change. You'll emerge not just as a more skilled Unity developer, but as a well-rounded software engineer equipped with industry-leading design patterns.
Table of Contents (23 chapters)
21
Other Books You May Enjoy
22
Index

Memento pattern variations

In some cases, the plain Memento pattern is enough to get things rolling, but there will always be situations where more features are needed to make your project the best version of itself. For instance, storing a single Memento object is usable but not ideal for scenarios where you want to have a history of data snapshots that can be undone and redone at your convenience, or injecting an Originator instance into your Caretaker class constructor (yes, it’s more coupling, but it also puts all the memento management responsibilities into a single place).

Again, these are optional, but I’ve found them extremely useful in my own projects (hopefully they spark your creativity when thinking of different ways to apply the Memento pattern in your own code).

Storing memento history

The Memento pattern is one of the best go-to solutions for creating a robust undo/redo system, so let’s write a basic implementation to see how it works...