# drflower/towerdefense-gameframework-demo architecture

> Architecture diagram of the GitHub repository drflower/towerdefense-gameframework-demo, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-06-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/drflower/towerdefense-gameframework-demo
- Repository: https://github.com/drflower/towerdefense-gameframework-demo

## Overview

1. This is a Unity 2019.4 project built around the open-source GameFramework library. The repository is split cleanly into a reusable framework layer under `Assets/GameFramework` and game-specific code/content under `Assets/GameMain`.

2. The startup boundary is the `GameEntry` / `GameFrameworkComponent` setup in `Assets/GameMain/Scripts/Base` and `Assets/GameFramework/Scripts/Runtime/Base`. The `GameStart` scene is the entry scene, then the game flows into menu and level scenes through a procedure/state machine rather than direct scene scripts.

3. Game flow is driven by the Procedure module. In `Assets/GameMain/Scripts/Procedure` you can see the startup pipeline: launch, splash, version check, resource check, resource init/update, preload, menu, level, and change-scene procedures. This is the high-level orchestration layer for the whole app.

4. Content is data-driven. Excel-authored tables are exported to `Assets/GameMain/DataTables` as both text and binary versions, with generated row classes in `Assets/GameMain/Scripts/DataTable`. Runtime game data objects in `Assets/GameMain/Scripts/Data` and `Assets/GameMain/Scripts/Data/*` wrap those tables into strongly-typed domain models for levels, towers, enemies, waves, UI, sounds, and settings.

5. The resource pipeline is a major architectural boundary. `Assets/GameFramework/Scripts/Editor/Resource*` contains the analyzer, builder, pack builder, and sync tools; `Assets/GameMain/Configs/*.xml` controls how assets are grouped and packed. At runtime, `ResourceComponent` and the framework resource managers load assets, scenes, and version lists, supporting both editor mode and updatable packaged mode.

6. Hot update is first-class. The README calls out version checking, basic-resource updates, and per-level split packages. Runtime update-related code lives in `ProcedureCheckVersion`, `ProcedureUpdateVersion`, `ProcedureCheckResources`, and `ProcedureUpdateResources`, while the framework’s `WebRequest` and `Download` modules provide the transport layer for fetching version lists and bundles.

7. The gameplay presentation layer is built on GameFramework’s Entity, Item, and UI modules. Game-specific entity logic in `Assets/GameMain/Scripts/Entity/EntityLogic` maps to prefab assets in `Assets/GameMain/Entity`, while item logic in `Assets/GameMain/Scripts/Item` maps to UI/gameplay interaction prefabs like placement tiles. UI screens are defined in `Assets/GameMain/UI/UIForms` and implemented in `Assets/GameMain/Scripts/UI`.

8. The core tower-defense mechanics are split into domain subsystems: `Level`, `Tower`, `PlacementArea`, and `Entity`. Level management handles map/level state and wave progression, placement-area code decides where towers can be built, tower code handles targeting/launching/upgrade logic, and entity code covers the spawned actors and effects.

9. Enemy behavior is state-driven. `Assets/GameMain/Scripts/FSM` contains movement and attack states for ground and flying enemies, including bypass behavior for flying units and attack transitions when pathing is blocked. This sits on top of the framework FSM module, which provides the generic state machine infrastructure.

10. Combat is event-oriented. Game-specific event args in `Assets/GameMain/Scripts/Event` represent major gameplay changes such as spawning enemies, starting waves, changing HP/energy, building/selling/upgrading towers, showing/hiding preview towers, and reloading levels. These events decouple UI, level logic, and entity spawning.

11. Localization is layered over both runtime data and resource variants. Language dictionaries live in `Assets/GameMain/Localization`, while runtime helpers in `Assets/GameMain/Scripts/Localization` and the framework localization module load the correct language content. The README notes that localization uses the resource system’s variant support.

12. Memory and object lifetime are managed with framework-level infrastructure. `ReferencePool`, `ObjectPool`, and related reusable event-args types are used heavily to reduce allocations; the project README explicitly calls out reference pooling as a core optimization. There is also a `TaskPool` and async loading infrastructure supporting resource and download workflows.

13. The framework itself is modular and reusable. `Assets/GameFramework/Libraries/GameFramework` contains generic subsystems such as file system, config, data table, debugger, event pool, FSM, localization, scene, sound, UI, utility, network, web request, and resource management. `Assets/GameFramework/Scripts/Runtime` provides the Unity-facing components and default helper implementations for those modules.

14. Tooling is an important part of the repo. `Assets/GameFramework/Scripts/Editor` and `Assets/GameMain/Scripts/Editor` contain inspectors, resource analyzers/builders, data-table generators, enum generators, and localization dictionary generators. This means a diagram should show both runtime and authoring/build-time paths, not just gameplay runtime.

15. The asset layout mirrors the runtime modules: scenes under `Assets/GameMain/Scenes`, prefabs under `Assets/GameMain/UI`, `Entity`, and `Item`, audio under `Sounds`, and level-specific resources under `Res/Scenes/Levels`. This separation is what enables the game’s per-level packaging and update strategy.

Main entry points: [`Assets/GameMain/Scripts/Procedure`](https://github.com/drflower/towerdefense-gameframework-demo/tree/master/Assets/GameMain/Scripts/Procedure) (Procedure Flow), [`Assets/GameMain/Scripts/Level/LevelManager.cs`](https://github.com/drflower/towerdefense-gameframework-demo/blob/master/Assets/GameMain/Scripts/Level/LevelManager.cs) (Level Gameplay), [`Assets/GameMain/Res`](https://github.com/drflower/towerdefense-gameframework-demo/tree/master/Assets/GameMain/Res) (Assets & Prefabs), [`Assets/GameFramework/Scripts/Runtime/Resource/ResourceComponent.cs`](https://github.com/drflower/towerdefense-gameframework-demo/blob/master/Assets/GameFramework/Scripts/Runtime/Resource/ResourceComponent.cs) (Resource System)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_framework["GameFramework"]
  node_gfbase["Framework Core<br/>runtime core"]
  node_resource["Resource System<br/>asset loading"]
  node_webdownload["Web & Download<br/>transport"]
  node_scene["Scene System<br/>scene loading<br/>[SceneComponent.cs]"]
  node_ui["UI System<br/>ui runtime<br/>[UIComponent.cs]"]
  node_entity["Entity System<br/>entity runtime<br/>[EntityComponent.cs]"]
  node_item["Item System<br/>item runtime<br/>[ItemComponent.cs]"]
  node_fsm["FSM System<br/>state machine<br/>[FsmComponent.cs]"]
  node_loc["Localization<br/>language runtime"]
  node_data["DataTable System<br/>table runtime"]
end

subgraph group_game["GameMain"]
  node_gameentry["GameEntry<br/>startup bootstrap<br/>[GameEntry.cs]"]
  node_procedure["Procedure Flow<br/>game flow"]
  node_gameplay["Level Gameplay<br/>tower defense<br/>[LevelManager.cs]"]
  node_entitiesgame["Game Entities<br/>game entity logic"]
  node_itemsgame["Game Items<br/>game item logic"]
  node_uigame["Game UI"]
  node_datamodels["Game Data<br/>domain models"]
  node_tables[("Data Tables<br/>authored tables")]
  node_content["Assets & Prefabs<br/>game content"]
end

subgraph group_pipeline["Build & Update"]
  node_tools["Editor Tools<br/>authoring tools"]
  node_resourcesrc["Asset Configs<br/>resource config"]
  node_datatablegen["Table Gen<br/>code generation"]
end

node_gameentry -->|"bootstraps"| node_gfbase
node_gameentry -->|"starts flow"| node_procedure
node_procedure -->|"checks/loads"| node_resource
node_procedure -->|"changes scenes"| node_scene
node_procedure -->|"opens screens"| node_ui
node_procedure -->|"orchestrates"| node_gameplay
node_resource -->|"fetches"| node_webdownload
node_resource -->|"loads assets"| node_content
node_resource -->|"uses config"| node_resourcesrc
node_tools -->|"edits"| node_resourcesrc
node_tools -->|"generates"| node_datatablegen
node_datatablegen -->|"exports"| node_tables
node_tables -->|"typed by"| node_datamodels
node_data -->|"reads"| node_tables
node_loc -->|"loads dictionaries"| node_content
node_gameplay -->|"spawns actors"| node_entitiesgame
node_gameplay -->|"uses items"| node_itemsgame
node_gameplay -->|"drives AI"| node_fsm
node_gameplay -->|"updates HUD"| node_ui
node_entitiesgame -->|"implements"| node_entity
node_itemsgame -->|"implements"| node_item
node_uigame -->|"implements"| node_ui
node_entitiesgame -->|"uses prefabs"| node_content
node_itemsgame -->|"uses prefabs"| node_content
node_uigame -->|"uses forms"| node_content
node_gameplay -->|"consumes"| node_datamodels
node_procedure -->|"selects language"| node_loc

click node_gameentry "https://github.com/drflower/towerdefense-gameframework-demo/blob/master/Assets/GameMain/Scripts/Base/GameEntry.cs"
click node_gfbase "https://github.com/drflower/towerdefense-gameframework-demo/tree/master/Assets/GameFramework/Libraries/GameFramework/Base"
click node_procedure "https://github.com/drflower/towerdefense-gameframework-demo/tree/master/Assets/GameMain/Scripts/Procedure"
click node_resource "https://github.com/drflower/towerdefense-gameframework-demo/blob/master/Assets/GameFramework/Scripts/Runtime/Resource/ResourceComponent.cs"
click node_webdownload "https://github.com/drflower/towerdefense-gameframework-demo/blob/master/Assets/GameFramework/Libraries/GameFramework/WebRequest/WebRequestManager.cs"
click node_scene "https://github.com/drflower/towerdefense-gameframework-demo/blob/master/Assets/GameFramework/Scripts/Runtime/Scene/SceneComponent.cs"
click node_ui "https://github.com/drflower/towerdefense-gameframework-demo/blob/master/Assets/GameFramework/Scripts/Runtime/UI/UIComponent.cs"
click node_entity "https://github.com/drflower/towerdefense-gameframework-demo/blob/master/Assets/GameFramework/Scripts/Runtime/Entity/EntityComponent.cs"
click node_item "https://github.com/drflower/towerdefense-gameframework-demo/blob/master/Assets/GameFramework/Scripts/Runtime/Item/ItemComponent.cs"
click node_fsm "https://github.com/drflower/towerdefense-gameframework-demo/blob/master/Assets/GameFramework/Scripts/Runtime/Fsm/FsmComponent.cs"
click node_loc "https://github.com/drflower/towerdefense-gameframework-demo/blob/master/Assets/GameFramework/Scripts/Runtime/Localization/LocalizationComponent.cs"
click node_data "https://github.com/drflower/towerdefense-gameframework-demo/blob/master/Assets/GameFramework/Scripts/Runtime/DataTable/DataTableComponent.cs"
click node_tools "https://github.com/drflower/towerdefense-gameframework-demo/tree/master/Assets/GameFramework/Scripts/Editor"
click node_resourcesrc "https://github.com/drflower/towerdefense-gameframework-demo/blob/master/Assets/GameMain/Configs/ResourceBuilder.xml"
click node_datatablegen "https://github.com/drflower/towerdefense-gameframework-demo/tree/master/Assets/GameMain/Scripts/Editor/DataTableGenerator"
click node_gameplay "https://github.com/drflower/towerdefense-gameframework-demo/blob/master/Assets/GameMain/Scripts/Level/LevelManager.cs"
click node_entitiesgame "https://github.com/drflower/towerdefense-gameframework-demo/tree/master/Assets/GameMain/Scripts/Entity/EntityLogic"
click node_itemsgame "https://github.com/drflower/towerdefense-gameframework-demo/tree/master/Assets/GameMain/Scripts/Item"
click node_uigame "https://github.com/drflower/towerdefense-gameframework-demo/tree/master/Assets/GameMain/Scripts/UI"
click node_datamodels "https://github.com/drflower/towerdefense-gameframework-demo/tree/master/Assets/GameMain/Scripts/Data"
click node_tables "https://github.com/drflower/towerdefense-gameframework-demo/tree/master/Assets/GameMain/DataTables"
click node_content "https://github.com/drflower/towerdefense-gameframework-demo/tree/master/Assets/GameMain/Res"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_gfbase,node_resource,node_webdownload,node_scene,node_ui,node_entity,node_item,node_fsm,node_loc,node_data toneBlue
class node_gameentry,node_procedure,node_gameplay,node_entitiesgame,node_itemsgame,node_uigame,node_datamodels,node_tables,node_content toneAmber
class node_tools,node_resourcesrc,node_datatablegen toneMint
```

## Components

### GameFramework

Reusable framework layer under Assets/GameFramework

- [Framework Core](https://github.com/drflower/towerdefense-gameframework-demo/tree/master/Assets/GameFramework/Libraries/GameFramework/Base): runtime core · Framework base entry, modules, pooling, tasks, and shared primitives · `Assets/GameFramework/Libraries/GameFramework/Base`
- [Resource System](https://github.com/drflower/towerdefense-gameframework-demo/blob/master/Assets/GameFramework/Scripts/Runtime/Resource/ResourceComponent.cs): asset loading · Runtime resource loading, version lists, update checks, and scene/asset access · `Assets/GameFramework/Scripts/Runtime/Resource/ResourceComponent.cs`
- [Web & Download](https://github.com/drflower/towerdefense-gameframework-demo/blob/master/Assets/GameFramework/Libraries/GameFramework/WebRequest/WebRequestManager.cs): transport · Network transport used for version checks and bundle downloads · `Assets/GameFramework/Libraries/GameFramework/WebRequest/WebRequestManager.cs`
- [Scene System](https://github.com/drflower/towerdefense-gameframework-demo/blob/master/Assets/GameFramework/Scripts/Runtime/Scene/SceneComponent.cs): scene loading · Scene load and unload management used by procedures · `Assets/GameFramework/Scripts/Runtime/Scene/SceneComponent.cs`
- [UI System](https://github.com/drflower/towerdefense-gameframework-demo/blob/master/Assets/GameFramework/Scripts/Runtime/UI/UIComponent.cs): ui runtime · UI forms, groups, helpers, and open/close lifecycle · `Assets/GameFramework/Scripts/Runtime/UI/UIComponent.cs`
- [Entity System](https://github.com/drflower/towerdefense-gameframework-demo/blob/master/Assets/GameFramework/Scripts/Runtime/Entity/EntityComponent.cs): entity runtime · Generic entity instancing and logic host for gameplay actors · `Assets/GameFramework/Scripts/Runtime/Entity/EntityComponent.cs`
- [Item System](https://github.com/drflower/towerdefense-gameframework-demo/blob/master/Assets/GameFramework/Scripts/Runtime/Item/ItemComponent.cs): item runtime · Generic item instancing and logic host for interactive world items · `Assets/GameFramework/Scripts/Runtime/Item/ItemComponent.cs`
- [FSM System](https://github.com/drflower/towerdefense-gameframework-demo/blob/master/Assets/GameFramework/Scripts/Runtime/Fsm/FsmComponent.cs): state machine · Generic state machine infrastructure used by game AI and flow · `Assets/GameFramework/Scripts/Runtime/Fsm/FsmComponent.cs`
- [Localization](https://github.com/drflower/towerdefense-gameframework-demo/blob/master/Assets/GameFramework/Scripts/Runtime/Localization/LocalizationComponent.cs): language runtime · Language dictionaries and localized string loading · `Assets/GameFramework/Scripts/Runtime/Localization/LocalizationComponent.cs`
- [DataTable System](https://github.com/drflower/towerdefense-gameframework-demo/blob/master/Assets/GameFramework/Scripts/Runtime/DataTable/DataTableComponent.cs): table runtime · Table loading and strongly-typed row access for authored game data · `Assets/GameFramework/Scripts/Runtime/DataTable/DataTableComponent.cs`

### GameMain

Tower defense game-specific code and content under Assets/GameMain

- [GameEntry](https://github.com/drflower/towerdefense-gameframework-demo/blob/master/Assets/GameMain/Scripts/Base/GameEntry.cs): startup bootstrap · Unity entry and component wiring for the game · `Assets/GameMain/Scripts/Base/GameEntry.cs`
- [Procedure Flow](https://github.com/drflower/towerdefense-gameframework-demo/tree/master/Assets/GameMain/Scripts/Procedure): game flow · Startup and scene orchestration through stateful procedures · `Assets/GameMain/Scripts/Procedure`
- [Level Gameplay](https://github.com/drflower/towerdefense-gameframework-demo/blob/master/Assets/GameMain/Scripts/Level/LevelManager.cs): tower defense · Core level, tower, placement, enemy, and combat domain logic · `Assets/GameMain/Scripts/Level/LevelManager.cs`
- [Game Entities](https://github.com/drflower/towerdefense-gameframework-demo/tree/master/Assets/GameMain/Scripts/Entity/EntityLogic): game entity logic · Game-specific entity logic mapped to prefabs for towers, enemies, projectiles, and effects · `Assets/GameMain/Scripts/Entity/EntityLogic`
- [Game Items](https://github.com/drflower/towerdefense-gameframework-demo/tree/master/Assets/GameMain/Scripts/Item): game item logic · Game-specific item logic for placement tiles and tower build interactions · `Assets/GameMain/Scripts/Item`
- [Game UI](https://github.com/drflower/towerdefense-gameframework-demo/tree/master/Assets/GameMain/Scripts/UI): game ui · Game-specific UI forms and UI components for menu, level, update, and pause screens · `Assets/GameMain/Scripts/UI`
- [Game Data](https://github.com/drflower/towerdefense-gameframework-demo/tree/master/Assets/GameMain/Scripts/Data): domain models · Typed runtime wrappers for levels, towers, enemies, waves, UI, sounds, settings, and assets · `Assets/GameMain/Scripts/Data`
- [Data Tables](https://github.com/drflower/towerdefense-gameframework-demo/tree/master/Assets/GameMain/DataTables): authored tables · Excel-authored text and binary tables consumed by runtime domain models · `Assets/GameMain/DataTables`
- [Assets & Prefabs](https://github.com/drflower/towerdefense-gameframework-demo/tree/master/Assets/GameMain/Res): game content · Scenes, prefabs, models, materials, sounds, and localized dictionaries · `Assets/GameMain/Res`

### Build & Update

Authoring, resource packing, and hot-update flow

- [Editor Tools](https://github.com/drflower/towerdefense-gameframework-demo/tree/master/Assets/GameFramework/Scripts/Editor): authoring tools · Inspectors, generators, and editor utilities for framework and game content · `Assets/GameFramework/Scripts/Editor`
- [Asset Configs](https://github.com/drflower/towerdefense-gameframework-demo/blob/master/Assets/GameMain/Configs/ResourceBuilder.xml): resource config · GameMain XML and config files that define asset grouping and packing · `Assets/GameMain/Configs/ResourceBuilder.xml`
- [Table Gen](https://github.com/drflower/towerdefense-gameframework-demo/tree/master/Assets/GameMain/Scripts/Editor/DataTableGenerator): code generation · Excel/table generation pipeline for row classes and data exports · `Assets/GameMain/Scripts/Editor/DataTableGenerator`

## Connections

- GameEntry → Framework Core: bootstraps · GameEntry initializes the reusable framework layer
- GameEntry → Procedure Flow: starts flow · Entry scene hands control to the procedure pipeline
- Procedure Flow → Resource System: checks/loads · Procedures coordinate version checks, updates, and resource initialization
- Procedure Flow → Scene System: changes scenes · Procedures drive loading of menu and level scenes
- Procedure Flow → UI System: opens screens · Procedures and flow states open menu, update, and gameplay UI
- Procedure Flow → Level Gameplay: orchestrates · Menu and level procedures transition into gameplay management
- Resource System → Web & Download: fetches · Resource update flow downloads version lists and bundles
- Resource System → Assets & Prefabs: loads assets · Runtime resource manager resolves scenes, prefabs, sounds, and other content
- Resource System → Asset Configs: uses config · Resource grouping and packing are driven by XML configuration
- Editor Tools → Asset Configs: edits · Editor resource tools consume project-specific resource config files
- Editor Tools → Table Gen: generates · Editor tooling generates table row classes and data exports
- Table Gen → Data Tables: exports · Generated outputs are written to text and binary table assets
- Data Tables → Game Data: typed by · Runtime domain models wrap raw tables into strongly-typed game data
- DataTable System → Data Tables: reads · Framework data table subsystem provides table row access
- Localization → Assets & Prefabs: loads dictionaries · Localization resolves language dictionaries from resource variants
- Level Gameplay → Game Entities: spawns actors · Level logic instantiates towers, enemies, projectiles, and effects
- Level Gameplay → Game Items: uses items · Placement and build interactions are mediated by item logic
- Level Gameplay → FSM System: drives AI · Enemy movement and attack behavior is state-machine driven
- Level Gameplay → UI System: updates HUD · Combat and wave state are surfaced through UI events and forms
- Game Entities → Entity System: implements · Game entity logic sits on top of the framework entity module
- Game Items → Item System: implements · Game item logic sits on top of the framework item module
- Game UI → UI System: implements · Game forms and helpers extend the framework UI module
- Game Entities → Assets & Prefabs: uses prefabs · Entity logic maps to prefab assets for towers, enemies, projectiles, and effects
- Game Items → Assets & Prefabs: uses prefabs · Item logic maps to placement and build prefabs
- Game UI → Assets & Prefabs: uses forms · UI screens are backed by prefab assets and localized content
- Level Gameplay → Game Data: consumes · Level, tower, enemy, wave, and settings models drive gameplay state
- Procedure Flow → Localization: selects language · Startup flow can initialize localization before UI and gameplay
