Use this guide to learn how TowerClash is structured at runtime and in the codebase: dependency injection, game states, gameplay modules, managers, and how models, views, and controllers fit together. Read it when onboarding as a programmer, tracing flow from GameStartBehaviour through GameState, or changing shared services and module lifecycles.

Overview TowerClash is a Unity tower defense/strategy game built with a modular, state-driven architecture using dependency injection and MVC-like patterns.

Core Architecture Patterns

  1. Dependency Injection (DI) System

Context.Install() and InstallByType()

Context.ApplyInstall()

Injector.Inject(target)

Why Install and Inject are both needed

Examples from this project

  1. State Management
  1. Observer Pattern

Project Structure

Managers (Scripts/Managers/) Core singleton services managing game systems:

Modules (Scripts/Modules/) Level-specific feature modules loaded during gameplay:

Game Entities (MVC-like Pattern)

UI Architecture (Scripts/UI/)

Configuration System (Scripts/Config/)

Data Persistence (Scripts/Domain/)

Entry Point GameStartBehaviour (MonoBehaviour):

Key Design Decisions

  1. Modular Level System: Gameplay features loaded as modules per level, allowing clean initialization/disposal
  2. Hierarchical Contexts: Sub-contexts for entities (structures, paths) enable isolated dependency injection
  3. State-Driven Architecture: Both high-level game flow and entity behavior use state machines
  4. Separation of Concerns: Clear separation between data (Models), presentation (Views), and logic (Controllers/Managers)
  5. Platform Integration: Built-in support for ads, IAP, and iOS privacy compliance