Learning Design Patterns with Unity Craft Reusable Code with Popular Software Design Patterns and Best Practices in Unity and C#

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 that will take your game development skills to the next level. With structured explanations backed with...

Descripción completa

Detalles Bibliográficos
Autor principal: Ferrone, Harrison (-)
Formato: Libro electrónico
Idioma:Inglés
Publicado: Birmingham : Packt Publishing, Limited 2024.
Edición:1st ed
Colección:Expert insight.
Materias:
Ver en Biblioteca Universitat Ramon Llull:https://discovery.url.edu/permalink/34CSUC_URL/1im36ta/alma991009825847706719
Tabla de Contenidos:
  • Cover
  • Copyright
  • Contributors
  • Table of Contents
  • Preface
  • Chapter 1: Priming the System
  • A word about software architecture
  • What are Design Patterns?
  • The Gang of Four
  • Pattern categories
  • Creational patterns
  • Behavioral patterns
  • Structural patterns
  • Why use Design Patterns?
  • When to use Design Patterns
  • Common pitfalls
  • About the example projects
  • Client code
  • Old vs new input system
  • Art assets
  • Summary
  • Further reading
  • Chapter 2: Managing Access with the Singleton Pattern
  • Technical requirements
  • Breaking down the pattern
  • UML diagramming
  • Pros and cons
  • Updating a MonoBehavior into a persistent Singleton
  • Persisting the Singleton between scenes
  • Testing for duplicate managers
  • Creating a generic Singleton
  • Adding thread safety to the generic Singleton
  • Thread locking during lazy instantiation
  • Creating Singletons as ScriptableObjects
  • Summary
  • Further reading
  • Chapter 3: Spawning Enemies with the Prototype Pattern
  • Technical requirements
  • Breaking down the Prototype pattern
  • Diagraming the pattern
  • Pros and cons
  • Implementing shallow and deep object copying
  • Adding a prototype interface
  • Making shallow object copies
  • Making deep object copies
  • Adding a prototype factory
  • Cloning prefabs
  • Creating a generic prototype Component
  • Summary
  • Further reading
  • Chapter 4: Creating Items with the Factory Method Pattern
  • Technical requirements
  • Breaking down the Factory Method pattern
  • Diagramming the pattern
  • Pros and cons
  • Declaring our inventory products
  • Adding a product interface
  • Creating concrete products
  • Working with different factory class variations
  • Adding an abstract factory class
  • Building a concrete factory
  • Creating a concrete factory class
  • Building a parameterized factory.
  • Creating a parameterized factory class
  • Scaling factories with reflection and LINQ
  • Adding GameObjects to the mix
  • Updating the Item class
  • Updating the Abstract Creator class
  • Updating the concrete factory
  • Updating the reflection factory
  • Extending products and factories with Scriptable Objects
  • Summary
  • Further reading
  • Chapter 5: Building a Crafting System with the Abstract Factory Pattern
  • Technical requirements
  • Breaking down the Abstract Factory pattern
  • Diagramming the pattern
  • Pros and cons
  • Creating related but independent products
  • Scripting product interfaces
  • Adding concrete products
  • Creating abstract and Concrete Factory classes
  • Writing a client class using only interfaces
  • Creating related and dependent products
  • Writing dependent product abstract classes
  • Creating concrete products
  • Adding abstract and Concrete Factory classes
  • Updating the client
  • Optional factory variations
  • Parameterized factories
  • Creating a factory of factories
  • Summary
  • Further reading
  • Chapter 6: Assembling Support Characters with the Builder Pattern
  • Technical requirements
  • Breaking down the Builder pattern
  • Diagramming the pattern
  • Pros and cons
  • Creating a base ally and builder interface
  • Scripting the product class
  • Declaring a common builder interface
  • Adding concrete builders
  • Using a director class
  • Integrating GameObjects
  • Transitioning to a Fluent Builder structure
  • Summary
  • Further reading
  • Chapter 7: Managing Performance and Memory with Object Pooling
  • Technical requirements
  • Breaking down the Object Pool pattern
  • Diagramming the pattern
  • Pros and cons
  • Writing an Object Pool class
  • Creating objects and filling the pool
  • Retrieving pooled objects
  • Releasing pooled objects
  • Resetting pooled objects
  • Object Pooling customizations.
  • Queues over lists
  • Thread-safe pools
  • Managing different pooled objects
  • Leveraging Unity's ObjectPool class
  • Summary
  • Further reading
  • Chapter 8: Binding Actions with the Command Pattern
  • Technical requirements
  • Breaking down the Command pattern
  • Diagramming the pattern
  • Reusable versus single-use commands
  • Pros and cons
  • Building a basic Command structure
  • Creating reusable commands
  • Adding a receiver
  • Adding an invoker class
  • Using an input listener
  • Updating the client
  • Creating coupled commands
  • Implementing an undo/redo system
  • Stacking commands
  • Adding an undo feature
  • Adding a redo feature
  • Confirming and clearing commands
  • Summary
  • Further reading
  • Chapter 9: Decoupling Systems with the Observer Pattern
  • Technical requirements
  • Breaking down the Observer pattern
  • Diagramming the pattern
  • Pros and cons
  • Creating a basic Observer structure
  • Writing the abstract base objects
  • Making the UI an observer
  • Subscribing observers and publishing events
  • Pattern strategies and optimizations
  • Choosing a communication strategy
  • Listening for different state changes
  • Cleaning up hanging resources
  • Using C# event types
  • Delegates and events
  • Updating to Action types
  • UnityEvents and the Inspector
  • Adding Unity events
  • Adding UnityEvent parameters
  • Persistent versus non-persistent events
  • The final boss - drag-and-drop system
  • Writing a ScriptableObject event
  • Creating listeners
  • Creating ScriptableObject event assets
  • Invoking the SOEvent
  • Connecting the system
  • Performance considerations
  • Picking the right implementation
  • Summary
  • Further reading
  • Chapter 10: Controlling Behavior with the State Pattern
  • Technical requirements
  • Breaking down the State pattern
  • A little automata theory
  • Diagramming the pattern
  • Pros and cons.
  • Creating a turn-based battle system
  • Defining abstract and base states
  • Creating a state machine
  • Protecting transitioning states
  • Subclassing state machines
  • Creating concrete states
  • Base state
  • Setup state
  • Player state
  • Enemy state
  • Ending state
  • Putting it all together
  • Initializing concrete states
  • Updating the client
  • Using a hierarchical state machine
  • Adapting for concurrent state machines
  • Unrelated concurrent states
  • Related concurrent states
  • Storing state history
  • Pushing new states
  • Reverting to previous states
  • Summary
  • Further reading
  • Chapter 11: Adding Features with the Visitor Pattern
  • Technical requirements
  • Breaking down the Visitor pattern
  • Diagramming the pattern
  • Pros and cons
  • Creating a save system
  • Structuring the interfaces
  • Adding a concrete Visitors
  • Adding concrete elements
  • Adding an object structure
  • Working with composite elements
  • Accounting for selective visitation
  • Summary
  • Further reading
  • Chapter 12: Swapping Algorithms with the Strategy Pattern
  • Technical requirements
  • Breaking down the Strategy pattern
  • Diagramming the pattern
  • Pros and cons
  • Creating a sorting system
  • Defining a strategy interface
  • Adding concrete strategies
  • Creating a context
  • Optimizing your strategies
  • Adding interchangeable strategies
  • Using default strategies
  • Strategies the Unity way
  • Upgrading to ScriptableObjects
  • Summary
  • Further reading
  • Chapter 13: Making Monsters with the Type Object Pattern
  • Technical requirements
  • Breaking down the Type Object pattern
  • Diagramming the pattern
  • Pros and cons
  • Creating monsters
  • Adding a Type Object
  • Configuring monsters
  • Optimization, inheritance, and behavior
  • Controlling allocation and initialization
  • Adding parent type objects
  • Sharing behavior isn't easy.
  • Creating ScriptableObject monsters
  • Summary
  • Further reading
  • Chapter 14: Taking Data Snapshots with the Memento Pattern
  • Technical requirements
  • Breaking down the Memento pattern
  • Diagramming the pattern
  • Pros and cons
  • Creating and restoring data snapshots
  • Adding the memento class
  • Setting up the caretaker
  • Updating the originator
  • Wiring up the client
  • Working with MonoBehaviours
  • Memento pattern variations
  • Storing memento history
  • Bundling originator and caretaker
  • Managers and ScriptableObject snapshots
  • Persisting data
  • Summary
  • Further reading
  • Chapter 15: Dynamic Upgrades with the Decorator Pattern
  • Technical requirements
  • Breaking down the Decorator pattern
  • Diagramming the pattern
  • Pros and cons
  • Building a simple Decorator
  • Adding a Component interface
  • Creating a concrete Component
  • Using a base Decorator
  • Building a concrete Decorator
  • Chaining multiple Decorators
  • Adding customized behaviors
  • Using ScriptableObject Decorators
  • Static vs dynamic decoration in action
  • Summary
  • Further reading
  • Chapter 16: Converting Incompatible Classes with the Adapter Pattern
  • Technical requirements
  • Breaking down the Adapter pattern
  • Diagramming the pattern
  • Pros and cons
  • Building a controller adapter
  • Defining a target
  • Adding the class adapter
  • Creating an object adapter class
  • Mapping properties in separate hierarchies
  • Summary
  • Further reading
  • Chapter 17: Simplifying Subsystems with the Façade Pattern
  • Technical requirements
  • Breaking down the Façade pattern
  • Diagramming the pattern
  • Pros and cons
  • Building a subsystem Façade
  • Defining subsystem objects
  • Initializing subsystems
  • Adding a public Façade method
  • Adding multiple Façade methods
  • Upgrading Façades
  • Summary
  • Further reading.
  • Chapter 18: Generating Terrains with the Flyweight Pattern.