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

About the example projects

When I first started learning about design patterns, I found the wealth of resources, tutorials, and applicable scenarios overwhelming (if this has happened to you too, I hope finding this book will make your journey much, much easier). The problem wasn’t the technical information that I was finding, but the way it was presented. More often than not, the design pattern content seemed to be shrouded in dry, overbearing technical language, complicated examples, or just plain old incorrect solutions.

One of my main goals in writing this book was to present the foundation of these wonderful tools with as little fluff as possible. However, this turns problematic when trying to find a balance between teaching the design pattern itself and getting it to run in a meaningful way – because just like design patterns, new skills wither and die in a vacuum. This is all to say that I’ve created the starter projects for each chapter as simply and meaningfully as I possibly can. The balance is delicate, and you might find the examples weighted to one side or the other, but it’s always been with the intention of making the design pattern the star.

Client code

Some of the ways I’ve implemented UI code, client scripts, or any of the simple systems around using each design pattern are not production-ready or best practices – they are the simplest way of using the pattern with context. On the flip side, I’ve given as much thought and page count as possible to pattern variations, extensions, and best practices so you have concrete tools to bring to your own projects.

Again, this book isn’t about Unity (although it’s a delightfully fun learning environment), but rather how we can learn problem solving skills and apply them to software.

Old vs new input system

As you’ll see in the next chapter and onwards, I’m using Unity’s old Input System rather than the new Input System. Why? Because it’s the simplest way to get the client code running with a minimum amount of setup and screenshots for you to follow. I love the new input system (I feel I need to put this on the record or risk banishment), but it does require a little specialized knowledge and experience that doesn’t contribute to design patterns. As always, I encourage you to experiment with implementing the design pattern solutions in whatever context works best for your project. For learning, I’ve found the old Input System works best.

Art assets

I love beautiful Unity projects that are full of life, sound, ambiance, and thematic feeling, but these things don’t help us learn new skills – in fact, they tend to distract at best and hinder at worst. All example projects use the most basic primitive objects and materials possible (essentially white boxing everything), not only to keep things consistent but to keep you focused on the design patterns. And who knows, the lack of excitement in our projects might just inspire you to deploy your new skills in ways you hadn’t thought of before.

I hope the simplicity of the examples I’ve prepared doesn’t make you nervous, because it should really make you hopeful. The fact that we can use these patterns as systems to be plugged in and interchanged with the UI, clients, or any other aspect of application development only strengthens the very first point of this chapter – design patterns are systems!