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

Making Monsters with the Type Object Pattern

In the last chapter, we worked on a system of interchangeable algorithms (strategies) that could be assigned at runtime or during gameplay without the client knowing the nitty-gritty details. In this chapter, we’re going to take a step back from behavior and put our sights on data and the Type Object pattern, which lets you create different configurations of the same object with the least number of classes (because all the cool kids use flat hierarchies).

Specifically, we’ll try to find common data that all related objects share, separate it out into its own class, and inject it back into the object we want to configure. You can create infinite combinations of the same object by giving them different types (shared data templates) without a huge class hierarchy that needs babysitting every time you add or modify the code!

For example, a hero or heroine could be a human, giant, or elf, but they all have hp, stamina,...