How drflower/towerdefense-gameframework-demo works
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: Procedure Procedure Flow · LevelManager.cs Level Gameplay · Res Assets & Prefabs · ResourceComponent.cs Resource System
Components 22
GameFramework
Reusable framework layer under Assets/GameFramework
- Framework Core · Framework base entry, modules, pooling, tasks, and shared primitives
Assets/GameFramework/Libraries/GameFramework/Base - Resource System · Runtime resource loading, version lists, update checks, and scene/asset access
Assets/GameFramework/Scripts/Runtime/Resource/ResourceComponent.cs - Web & Download · Network transport used for version checks and bundle downloads
Assets/GameFramework/Libraries/GameFramework/WebRequest/WebRequestManager.cs - Scene System · Scene load and unload management used by procedures
Assets/GameFramework/Scripts/Runtime/Scene/SceneComponent.cs - UI System · UI forms, groups, helpers, and open/close lifecycle
Assets/GameFramework/Scripts/Runtime/UI/UIComponent.cs - Entity System · Generic entity instancing and logic host for gameplay actors
Assets/GameFramework/Scripts/Runtime/Entity/EntityComponent.cs - Item System · Generic item instancing and logic host for interactive world items
Assets/GameFramework/Scripts/Runtime/Item/ItemComponent.cs - FSM System · Generic state machine infrastructure used by game AI and flow
Assets/GameFramework/Scripts/Runtime/Fsm/FsmComponent.cs - Localization · Language dictionaries and localized string loading
Assets/GameFramework/Scripts/Runtime/Localization/LocalizationComponent.cs - DataTable System · 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 · Unity entry and component wiring for the game
Assets/GameMain/Scripts/Base/GameEntry.cs - Procedure Flow · Startup and scene orchestration through stateful procedures
Assets/GameMain/Scripts/Procedure - Level Gameplay · Core level, tower, placement, enemy, and combat domain logic
Assets/GameMain/Scripts/Level/LevelManager.cs - Game Entities · Game-specific entity logic mapped to prefabs for towers, enemies, projectiles, and effects
Assets/GameMain/Scripts/Entity/EntityLogic - Game Items · Game-specific item logic for placement tiles and tower build interactions
Assets/GameMain/Scripts/Item - Game UI · Game-specific UI forms and UI components for menu, level, update, and pause screens
Assets/GameMain/Scripts/UI - Game Data · Typed runtime wrappers for levels, towers, enemies, waves, UI, sounds, settings, and assets
Assets/GameMain/Scripts/Data - Data Tables · Excel-authored text and binary tables consumed by runtime domain models
Assets/GameMain/DataTables - Assets & Prefabs · Scenes, prefabs, models, materials, sounds, and localized dictionaries
Assets/GameMain/Res
Build & Update
Authoring, resource packing, and hot-update flow
- Editor Tools · Inspectors, generators, and editor utilities for framework and game content
Assets/GameFramework/Scripts/Editor - Asset Configs · GameMain XML and config files that define asset grouping and packing
Assets/GameMain/Configs/ResourceBuilder.xml - Table Gen · Excel/table generation pipeline for row classes and data exports
Assets/GameMain/Scripts/Editor/DataTableGenerator
Connections 27
- 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