0%

Discover practical design propositions to resolve game programming challenges in Unity

Key Features

  • Get an overview of Unity engine architecture and coding model
  • Build a complete racing game using software design patterns and understand how to implement them in Unity
  • Download the source code of the complete prototype demonstrating each of the software patterns used

Book Description

Unity's coding model and architecture require knowledge of common software design patterns. To optimally code a game in Unity, in the same way you do in other engines, you'll have to adapt to programming techniques that involve the use of design patterns.

In this second edition, you'll get to grips with using design patterns with the help of supplemented code examples based on actual implementations of game mechanics and systems of a playable racing game prototype. You'll be introduced to the core principles of reusable software patterns and how to employ them to build components efficiently. Some notable additions include a game design document (GDD), a Unity programming primer, and the downloadable source code of a complete prototype.

You'll start by learning about the overall design of the core game mechanics and systems that you'll be building throughout this Unity book, and discover tried-and-tested software patterns to code essential components of a game in a structured manner. You'll also find out how you can use classic design patterns to utilize Unity's unique API features. Finally, you'll identify the negative impacts of bad architectural decisions and understand how to overcome them with simple but effective practices.

By the end of this book, you'll be able to develop Unity games in a structured, scalable, and optimized way.

What you will learn

  • Structure professional Unity code using industry-standard development patterns
  • Identify the right patterns for implementing specific game mechanics or features
  • Develop configurable core game mechanics and ingredients that can be modified without writing a single line of code
  • Review practical object-oriented programming (OOP) techniques and learn how they're used in the context of a Unity project
  • Build unique game development systems such as a level editor
  • Explore ways to adapt traditional design patterns for use with the Unity API

Who this book is for

This book is for Unity game developers who want to learn industry standards for building Unity games. Knowledge of the Unity game engine and programming in the C# language is expected. If you're only just starting your journey to becoming a Unity game developer, this book is not suitable for you.

Table of Contents

  1. Title Page
  2. Copyright and Credits
    1. Game Development Patterns with Unity 2021 Second Edition
  3. Dedication
  4. Contributors
    1. About the author
    2. About the reviewers
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
    4. Download the example code files
    5. Code in Action
    6. Download the color images
    7. Conventions used
    8. Get in touch
    9. Share Your Thoughts
  6. Sections 1: Fundamentals
  7. Before We Begin
    1. Notes about the new edition
    2. The philosophy of the book
    3. What are design patterns?
    4. Which subjects aren't covered in this book?
    5. The game project
    6. Summary
  8. The Game Design Document
    1. The design document
    2. Game overview
    3. Unique selling points
    4. Minimum requirements
    5. Game synopsis
    6. Game objectives
    7. Game rules
    8. Game loop
    9. Game environment
    10. Camera, control, character (3Cs)
    11. Camera
    12. Character
    13. Character description
    14. Character metrics
    15. Character states
    16. Controller
    17. Game ingredients
    18. Superbikes
    19. Pickups
    20. Obstacles
    21. Weaponry
    22. Game systems
    23. Game menu
    24. Game HUD
    25. Summary
    26. Further reading
  9. A Short Primer to Programming in Unity
    1. What you should already know
    2. C# language features
    3. Unity engine features 
    4. Summary
    5. Further reading
  10. Section 2: Core Patterns
  11. Implementing a Game Manager with the Singleton
    1. Technical requirements
    2. Understanding the Singleton pattern
    3. Benefits and drawbacks
    4. Designing a Game Manager
    5. Implementing the Game Manager
    6. Testing the Game Manager
    7. Summary
  12. Managing Character States with the State Pattern
    1. Technical requirements
    2. An overview of the State pattern
    3. Defining character states
    4. Implementing the State pattern
    5. Implementing the State pattern
    6. Testing the State pattern implementation
    7. Benefits and drawbacks of the State pattern
    8. Reviewing alternative solutions
    9. Summary
  13. Managing Game Events with the Event Bus
    1. Technical requirements
    2. Understanding the Event Bus pattern
    3. Benefits and drawbacks of the Event Bus pattern
    4. When to use the Event Bus
    5. Managing global race events
    6. Implementing a Race Event Bus
    7. Testing the Race Event Bus
    8. Reviewing the Event Bus implementation
    9. Reviewing some alternative solutions
    10. Summary
  14. Implement a Replay System with the Command Pattern
    1. Technical requirements
    2. Understanding the Command pattern
    3. Benefits and drawbacks of the Command pattern
    4. When to use the Command pattern
    5. Designing a replay system
    6. Implementing a replay system
    7. Implementing the replay system
    8. Testing the replay system
    9. Reviewing the implementation
    10. Reviewing alternative solutions
    11. Summary
  15. Optimizing with the Object Pool Pattern
    1. Technical requirements
    2. Understanding the Object Pool pattern
    3. Benefits and drawbacks of the Object Pool pattern
    4. When to use the Object Pool pattern
    5. Implementing the Object Pool pattern
    6. Steps for implementing the Object Pool pattern
    7. Testing the Object Pool implementation
    8. Reviewing the Object Pool implementation
    9. Reviewing alternative solutions
    10. Summary
  16. Decoupling Components with the Observer Pattern
    1. Technical requirements
    2. Understanding the Observer pattern
    3. Benefits and drawbacks of the Observer pattern
    4. When to use the Observer pattern
    5. Decoupling core components with the Observer pattern
    6. Implementing the Observer pattern
    7. Testing the Observer pattern implementation
    8. Reviewing alternative solutions
    9. Summary
  17. Implementing Power-Ups with the Visitor Pattern
    1. Technical requirements
    2. Understanding the Visitor pattern
    3. Benefits and drawbacks of the Visitor pattern
    4. Designing a power-up mechanic
    5. Implementing a power-up mechanic
    6. Implementing the power-up system
    7. Testing the power-up system implementation
    8. Reviewing the power-up system implementation
    9. Summary
  18. Implementing a Drone with the Strategy Pattern
    1. Technical requirements
    2. Understanding the Strategy pattern
    3. Benefits and drawbacks of the Strategy pattern
    4. When to use the Strategy pattern
    5. Designing an enemy drone
    6. Implementing an enemy drone
    7. Steps to implementing an enemy drone
    8. Testing the enemy drone implementation
    9. Reviewing the enemy drone implementation
    10. Reviewing alternative solutions
    11. Summary
  19. Using the Decorator to Implement a Weapon System
    1. Technical requirements
    2. Understanding the Decorator pattern
    3. Benefits and drawbacks of the Decorator pattern
    4. When to use the Decorator pattern
    5. Designing a weapon system
    6. Implementing a weapon system
    7. Implementing the weapon system
    8. Testing the weapon system
    9. Reviewing the weapon system
    10. Reviewing alternative solutions
    11. Summary
  20. Implementing a Level Editor with Spatial Partition
    1. Technical requirements
    2. Understanding the Spatial Partition pattern
    3. When to use the Spatial Partition pattern
    4. Designing a level editor
    5. Implementing a level editor
    6. Steps for implementing a level editor
    7. Using the level editor
    8. Reviewing the level-editor implementation
    9. Reviewing alternative solutions
    10. Summary
  21. Section 3: Alternative Patterns
  22. Adapting Systems with an Adapter
    1. Technical requirements
    2. Understanding the Adapter pattern
    3. Benefits and drawbacks of the Adapter pattern
    4. When to use the Adapter pattern
    5. Implementing the Adapter pattern
    6. Implementing the Adapter pattern
    7. Testing the Adapter pattern implementation
    8. Summary
  23. Concealing Complexity with a Facade Pattern
    1. Technical requirements
    2. Understanding the Facade pattern
    3. Benefits and drawbacks
    4. Designing a bike engine
    5. Implementing a bike engine
    6. Testing the engine facade
    7. Reviewing alternative solutions
    8. Summary
  24. Managing Dependencies with the Service Locator Pattern
    1. Technical requirements
    2. Understanding the Service Locator pattern
    3. Benefits and drawbacks of the Service Locator pattern
    4. When to use the Service Locator pattern
    5. Implementing a Service Locator pattern
    6. Testing the Service Locator pattern
    7. Reviewing alternative solutions
    8. Summary
  25. About Packt
    1. Why subscribe?
  26. Other Books You May Enjoy
    1. Packt is searching for authors like you
    2. Share Your Thoughts
54.198.108.174