How burnemdown/unitycorekit works
1. Repository role and boundary
UnityCoreKit is not an application; it is a reusable Unity library meant to be embedded as a Git submodule inside a host game project. The architecture is therefore a set of runtime services, utilities, and editor helpers that the consuming game wires together.
2. Top-level split: runtime vs editor
The codebase is cleanly separated into Runtime/ and Editor/ assemblies. Runtime contains all game-facing systems; Editor contains Unity editor tooling such as custom inspectors and helpers. This split is enforced with .asmdef files so runtime code does not depend on UnityEditor.
3. Bootstrap and composition root
Runtime/Bootstrap/Loader.cs is the expected entry point in the host project. It acts as the composition root: it creates the persistent bootstrap object, registers concrete service implementations, and wires the subsystem graph together. Most systems are consumed through interfaces, so the loader decides which implementations are active.
4. Central service registry
Core.Services.CoreServices is the main service locator/registry. It provides lazy registration and resolution of interfaces such as audio, analytics, save, scene loading, networking, remote config, time, events, factories, pooling, and localization. This is the central architectural boundary: gameplay code depends on interfaces, while the loader injects implementations.
5. Interfaces-first core contract
The Runtime/Core/Interfaces/ folder defines the stable API surface for the whole package. These interfaces are what the host game should target. The concrete services live elsewhere, making it easy to swap stubs for production systems without changing consuming code.
6. Default, stub, and optional production services
There are three main service families:
- DefaultServices/ for functional Unity-backed implementations like time, scene loading, JSON save, and basic network support.
- StubServices/ for no-op or logging implementations of audio, localization, analytics, crash reporting, and remote config.
- DefaultServices/Firebase/ for optional Firebase-backed analytics, crash reporting, and remote config.
This indicates a “safe-by-default” design: the library works without external backend SDKs, but can override stubs when Firebase is available.
7. Object creation and pooling pipeline
Object creation is abstracted through IObjectFactory and then reused by PoolManager. Factory implementations include:
- AddressablesFactory for Addressables-based asset loading/instantiation
- PrefabFactory for direct prefab-map instantiation
- CompositeFactory to choose between them
The flow is: resolve factory by key → create object asynchronously → optionally route through pooling. This is the main content-loading and reuse path in the package.
8. Event-driven messaging subsystem
Core.Events provides a lightweight event bus via IEventsManager, with EventType and listener metadata. EventListenerManager tracks subscriptions and helps with cleanup. The design is central-dictionary based and supports safe listener changes while events are being processed. This is the primary internal messaging boundary between systems.
9. User interaction as a higher-level layer
Runtime/UserInteractions/ sits above the generic event system. It translates Unity input/pointer behavior into semantic interaction events, using UserInteractionsService and Unity source adapters like PointerClickUserInteractionSource. This module depends on Core.Events, but not vice versa, so the dependency direction is one-way: raw input becomes domain-level interaction events.
10. Update loop management
UpdateManager, FixedUpdateManager, and LateUpdateManager centralize per-frame observer dispatch. Systems implement observer interfaces and register with the relevant manager instead of each component owning its own Unity update method. This creates a controllable and inspectable update boundary, useful for ordering and throttling.
11. Async, threading, and Unity main-thread safety
MainThreadDispatcher is a runtime utility that queues actions onto Unity’s main thread. TaskExtensions build on that to allow async continuations to safely touch Unity objects. This is an important infrastructure boundary because several systems—factories, loading, and service initialization—can run asynchronously but must re-enter the main thread for Unity API calls.
12. Persistence and data storage
JsonFileSaveSystem implements ISaveSystem using JSON files stored under Application.persistentDataPath, with Newtonsoft Json as the serialization dependency. Saves are slot-based and version-aware, which makes the save system a separate persistence boundary rather than an in-memory cache.
13. Utility layer
Core/Utils/ contains shared infrastructure that many subsystems depend on: logging, prefab and dictionary helpers, layer attributes, JSON object helpers, and game-object extensions. Logger centralizes debug output and is compiled conditionally, so logging can be disabled globally in production builds.
14. Editor tooling
The Editor/ folder contains support tools for the Unity editor only, such as custom drawers and inspector locking/opening utilities. These do not participate in runtime data flow, but they support authoring and debugging of the runtime systems.
15. External dependencies that affect architecture
The package materially depends on Unity Addressables for asset loading and Newtonsoft Json for save serialization. Firebase is optional and isolated behind compile-time/runtime checks. This means the core architecture is designed to function without backend services, while still allowing production integrations to be swapped in through the same interface layer.
Main entry points: Loader.cs Loader · CoreServices.cs Core Services · DefaultSceneLoader.cs Default Services · CompositeFactory.cs Factory Pipeline
Components 18
Runtime Core
Runtime services, contracts, and infrastructure
- Loader · Entry point that composes and registers runtime services
Runtime/Bootstrap/Loader.cs - Core Services · Central lazy registry and resolver for runtime services
Runtime/Core/Services/CoreServices.cs - Contracts · Stable service interfaces consumed by host gameplay code
Runtime/Core/Interfaces/IServices.cs - Default Services · Core runtime implementations such as time, scene loading, and networking
Runtime/Core/DefaultServices/DefaultSceneLoader.cs - Stub Services · Safe default implementations for optional services
Runtime/Core/StubServices/StubAudioManager.cs - Firebase Services · Firebase-backed analytics, crash reporting, and remote config
Runtime/Core/DefaultServices/Firebase/FirebaseInitializer.cs - Event API · Event types and listener metadata shared across systems
Runtime/Core/Events/EventType.cs - Events Manager · Central event dispatch and listener management
Runtime/Core/Services/EventsManager.cs - Factory Pipeline · Factory selection and object creation abstraction
Runtime/Core/Services/CompositeFactory.cs - Pool Manager · Reuses created objects through pooling
Runtime/Core/Services/PoolManager.cs - Update Managers · Centralized Update, FixedUpdate, and LateUpdate observer dispatch
Runtime/Core/UpdateManagers/UpdateManager.cs - Main Thread · Queues work back onto Unity's main thread
Runtime/Core/Utils/MainThreadDispatcher.cs - Save System · Slot-based JSON file save/load under persistent data path
Runtime/Core/DefaultServices/JsonFileSaveSystem.cs - Utils · Cross-cutting helpers for logging, JSON, prefabs, and tasks
Runtime/Core/Utils/Logs/Logger.cs
User Interactions
Input-to-domain interaction layer
- Interaction API · User interaction abstractions and event types
Runtime/UserInteractions/IUserInteractions.cs - Interaction Service · Maps input source behavior into semantic interaction events
Runtime/UserInteractions/Services/UserInteractionsService.cs - Pointer Source · Unity pointer-click adapter feeding the interaction layer
Runtime/UserInteractions/Unity/PointerClickUserInteractionSource.cs
Editor
Unity editor-only tooling
- Editor Tools · Editor-only drawers and loader utilities
Editor/OpenLoaderTool.cs
Connections 30
- Loader → Core Services: compose · Bootstraps and wires the central service registry
- Loader → Default Services: register · Installs runtime implementations into the service graph
- Loader → Stub Services: fallbacks · Uses stubs for optional services when no backend is present
- Loader → Firebase Services: optional · Enables Firebase-backed implementations when available
- Loader → Events Manager: wire · Initializes the event subsystem early in startup
- Loader → Factory Pipeline: wire · Connects object creation implementations
- Loader → Pool Manager: wire · Registers pooling alongside factories
- Loader → Update Managers: wire · Sets up frame-driven observer dispatch
- Loader → Save System: wire · Makes save/load available through services
- Core Services → Contracts: resolves · Provides interface-first access to runtime systems
- Core Services → Events Manager: hosts · Owns the event bus as a core service
- Core Services → Factory Pipeline: hosts · Exposes factory selection and creation
- Core Services → Pool Manager: hosts · Exposes object pooling as a shared service
- Core Services → Save System: hosts · Registers the save system implementation
- Core Services → Default Services: binds · Maps service interfaces to default Unity-backed implementations
- Core Services → Stub Services: binds · Maps optional interfaces to safe defaults
- Core Services → Firebase Services: overrides · Can replace stubs with Firebase-backed services
- Events Manager → Event API: uses · Dispatches typed events and listener metadata
- Interaction Service → Interaction API: emits · Produces semantic user interaction events
- Pointer Source → Interaction Service: feeds · Turns Unity pointer clicks into interaction requests
- Interaction Service → Events Manager: publishes · Uses the event bus to broadcast interactions
- Factory Pipeline → Main Thread: syncs · Re-enters Unity main thread for object creation work
- Factory Pipeline → Utils: uses · Relies on shared helpers and logging support
- Pool Manager → Factory Pipeline: wraps · Pools objects created by the factory layer
- Update Managers → Utils: uses · Shares logging and extension helpers
- Default Services → Main Thread: uses · Re-enters Unity safely after async work
- Default Services → Utils: uses · Depends on shared runtime utilities
- Firebase Services → Default Services: extends · Optional backend services sit beside the default implementations
- Editor Tools → Loader: supports · Editor helpers help open and inspect the runtime bootstrap
- Editor Tools → Contracts: supports · Editor tooling assists authoring against runtime contracts