How ellanjiang/gameframework works
Project Type and Purpose
• This is a client-side Unity game framework library (written in C#) that provides 19 built-in modules (e.g., Resource, UI, Entity, Network, etc.) to standardize and accelerate Unity game development.
• It is not a traditional front-end/back-end web app or microservices suite, but rather a monolithic, modular, extensible SDK integrated into a Unity project.
Directory Structure Analysis
• Top-level “GameFramework” folder contains dozens of subfolders, each named for one of the 19 modules plus “Base,” “Utility,” and other cross-cutting concerns.
• Each module folder contains a Manager class (e.g., ResourceManager.cs), interfaces (e.g., IResourceManager.cs, IResourceHelper.cs), event args, and callback types.
• “Base” houses core services: entry point (GameFrameworkEntry), module registration (GameFrameworkModule), event bus (EventPool), task pool, reference pool, logging, serialization, data providers, etc.
• “Utility” contains helpers for JSON, encryption, compression, random, path, text, verification—common routines used across modules.
Key Architectural Patterns
• Modular architecture: each feature is its own “GameFramework/ModuleName” with a Manager, interfaces for helpers, and events/callbacks.
• Event-driven: central EventPool facilitates decoupled communication—modules publish events (e.g., DownloadSuccessEventArgs) and game logic subscribes.
• Asynchronous pipelines: Resource → Download/WebRequest → FileSystem → DataTable/DataNode → Entity/UI/Scene.
• Factory/provider pattern: DataProviderCreator, IResourceHelper, IWebRequestAgentHelper allow swapping platform-specific implementations.
• Finite State Machines: FSM and Procedure modules manage in-game state transitions.
• Object pooling: ObjectPool module reuses GameObject or data instances to reduce GC and Instantiate/Destroy overhead.
Main Components
A. Core Foundation
• GameFrameworkEntry (bootstrap)
• GameFrameworkModule registry
• EventPool (event bus)
• TaskPool (background tasks)
• ReferencePool, Serializer, Logger
B. Feature Modules (grouped by concern)
1. Data & Configuration: ConfigManager, DataTableManager, DataNodeManager
2. Resource Management: ResourceManager (async loader), DownloadManager, WebRequestManager, FileSystemManager
3. Runtime Logic: EntityManager, UIManager, SceneManager, SoundManager, ProcedureManager, FsmManager
4. Utilities & Services: LocalizationManager, SettingManager, NetworkManager, DebuggerManager, ObjectPoolManager
C. External Integration
• Unity Engine (MonoBehaviour entry, Update loop)
• Platform-specific helpers (IResourceHelper, IFileSystemHelper, IWebRequestAgentHelper, etc.)
• User-provided modules (custom ProcedureBase, UIFormLogic, Packet subclasses)
Relationships and Interactions
• At startup, Unity invokes GameFrameworkEntry → registers modules via GameFrameworkModule → each Manager.Initialize().
• Game logic triggers operations (e.g., LoadScene) → calls SceneManager → ResourceManager → Download/WebRequest → FileSystem → ResourceLoader → EventPool publishes load completion → SceneManager spawns scene.
• EntityManager and UIManager also request assets via ResourceManager, subscribe to progress and completion events.
• NetworkManager manages socket channels, dispatches incoming packets via EventPool.
• DebuggerManager hooks into EventPool to display runtime logs and custom debug windows.
• FSM and ProcedureManager use EventPool and TaskPool to tick and transition states asynchronously.