Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Learning Design Patterns with Unity

You're reading from   Learning Design Patterns with Unity Learn the secret of popular design patterns while building fun, efficient games in Unity 2023 and C#

Arrow left icon
Product type Paperback
Published in May 2024
Publisher Packt
ISBN-13 9781805120285
Length 676 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Harrison Ferrone Harrison Ferrone
Author Profile Icon Harrison Ferrone
Harrison Ferrone
Arrow right icon
View More author details
Toc

Table of Contents (23) Chapters Close

Preface 1. Priming the System FREE CHAPTER 2. Managing Access with the Singleton Pattern 3. Spawning Enemies with the Prototype Pattern 4. Creating Items with the Factory Method Pattern 5. Building a Crafting System with the Abstract Factory Pattern 6. Assembling Support Characters with the Builder Pattern 7. Managing Performance and Memory with Object Pooling 8. Binding Actions with the Command Pattern 9. Decoupling Systems with the Observer Pattern 10. Controlling Behavior with the State Pattern 11. Adding Features with the Visitor Pattern 12. Swapping Algorithms with the Strategy Pattern 13. Making Monsters with the Type Object Pattern 14. Taking Data Snapshots with the Memento Pattern 15. Dynamic Upgrades with the Decorator Pattern 16. Converting Incompatible Classes with the Adapter Pattern 17. Simplifying Subsystems with the Façade Pattern 18. Generating Terrains with the Flyweight Pattern 19. Global Access with the Service Locator Pattern 20. The Road Ahead 21. Other Books You May Enjoy
22. Index

What this book covers

Chapter 1, Priming the System, starts off with a brief trip into software architecture, software design, and design pattern categories, all while getting comfortable with the why and when of implementing these solutions. We’ll also go over the common pitfalls of using design patterns for the first time and the example projects used throughout the book.

Chapter 2, Managing Access with the Singleton Pattern, begins by laying the groundwork for uses-cases where globally accessible classes are needed (like persistent game managers) and moves on to generic singleton classes, thread-safety, and converting singletons into ScriptableObjects.

Chapter 3, Spawning Enemies with the Prototype Pattern, takes a deep dive into efficiently creating objects without the memory overhead by copying instead of instantiating new instances. We’ll also cover the differences between shallow and deep object copying in C#, clone prefab objects, and build a generic cloning script component.

Chapter 4, Creating Items with the Factory Method Pattern, introduces the concept of object factories that can produce a variety of products, different factory variations we can use to make our code more efficient and flexible, and scale factory production with Reflection and LINQ.

Chapter 5, Building a Crafting System with the Abstract Factory Pattern, details the process for creating factories of factories, working with families of related and independent (or dependent) products, and finally exploring Abstract Factory variations for niche scenarios.

Chapter 6, Assembling Support Characters with the Builder Pattern, delves into an assembly line approach to creating complex objects using the same construction processes to pump out different products. We’ll also add GameObjects to the mix and use the fluent Builder pattern variation for cleaner code.

Chapter 7, Managing Performance and Memory with Object Pooling, introduces the concept of recycling batches of objects for reuse instead of creating new instances from scratch while incorporating thread-safety and Unity’s own generic ObjectPool class.

Chapter 8, Binding Actions with the Command Pattern, starts with an overview of actionable requests and pre-packaging everything a command may need to be executed. We’ll also dive into the differences between coupled and uncoupled commands, their respective use cases, and how to build a complete undo/redo system from scratch.

Chapter 9, Decoupling Systems with the Observer Pattern, takes a more in-depth look at communication strategies between objects, how to effectively separate message senders from receivers, and the performance pros and cons of using native C# events versus Unity events.

Chapter 10, Controlling Behavior with the State Pattern, dives into the concept of managing an objects’ state, transitioning between states, and the basic theory behind state machines. We’ll also explore different configurations of state machines, including Finite state machines, Hierarchical state machines, and Concurrent state machines, as well as how to track and store state history.

Chapter 11, Adding Features with the Visitor Pattern, gets you ready to add new behaviors to existing objects without changing the underlying object in any way by creating a simple saving system. We’ll also learn how to deal with composite elements (objects with children) and how to convert our save system to use ScriptableObjects.

Chapter 12, Swapping Algorithms with the Strategy Pattern, explores how to configure classes and objects with interchangeable behaviors (or algorithms) at runtime by building a simple turn-based battle team example. We’ll also learn how to optimize these strategies for efficiency and update them to use ScriptableObjects.

Chapter 13, Making Monsters with the Type Object Pattern, takes a deep dive into separating common data that a group of related objects share and then creating different configurations of those objects with the least amount of classes using a flat hierarchy. We’ll also look at memory allocation and inheritance optimizations and learn how to incorporate ScriptableObjects as configurable data containers.

Chapter 14, Taking Data Snapshots with the Memento Pattern, introduces a system for storing, managing, and restoring an object’s internal state at any point in time using data snapshots without breaking the object’s encapsulation by building a character builder UI example.

Chapter 15, Dynamic Upgrades with the Decorator Pattern, offers solutions for dynamically adding behaviors to existing objects without subclassing, making a completely optional opt-in system for new upgrades and features.

Chapter 16, Converting Incompatible Classes with the Adapter Pattern, dives into creating shared interfaces for two or more classes that aren’t part of any shared hierarchies to work together. We’ll also touch on two variations (class and object adapters) and how to map properties in mismatched hierarchies.

Chapter 17, Simplifying Subsystems with the Façade Pattern, details a common solution for creating a wall between client code and complex (and often interdependent) subsystems by creating a simple auto-save feature. We’ll also get hands-on experience with adding multiplefaçade methods for clients to access and talk about creating abstract façade classes for certain scenarios.

Chapter 18, Generating Terrains with the Flyweight Pattern, introduces the concept of shareable state, which makes object creation (especially in large quantities) more computationally efficient if objects don’t have to store duplicate data. We’ll also discuss adding factories to this design pattern and how to correctly chose between the Flyweight and Type Object patterns.

Chapter 19, Global Access with the Service Locator Pattern, details a centralized solution for storing and locating systems in your projects that need to be globally accessible. Like singletons, these services may need to be persistent and accessible from anywhere, which means putting them into a single registry not only makes initialization easier, but it also makes them less prone to abuse.

Chapter 20, The Road Ahead, finishes with a look at the SOLID design principles, the design patterns we didn’t cover, and resources to take your programming skills to the next level.

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image