Factories
Description
Factories are responsible for creating game objects and entities in a controlled and extensible manner.
Using factories allows you to:
encapsulate object creation logic
integrate Zenject into the instantiation process
centralize configuration of created entities
Factories do not manage object behavior — they only handle creation and initial setup.
Built-in Factories
The template includes the following factory implementations:
1. WindowFactory
WindowFactory is used to centrally create and manage UI windows:
Stores the mapping between window types and prefabs
Uses
IInstantiatorto safely instantiate windows under the UI root (UIRoot)Provides type-safe access to window components
Separates UI display logic from direct prefab references, simplifying maintenance and extension
2. StatesFactory
StatesFactory provides centralized creation of game states through Zenject:
Holds a reference to the DI container
Provides
GetState<TState>()to retrieve any state implementingIExitableStateAutomatically resolves all state dependencies via DI
Note: This factory is not intended to be extended and should remain as implemented.
3. GameFactory
GameFactory handles creation of gameplay objects and components using Zenject and prefabs from GameplayAssetsConfig:
Uses
IInstantiatorto instantiate objects (projectiles, enemies, upgrade parts, tentacles)For UI elements such as
DamagePopuporEnemyKillRewardText, uses standardObject.Instantiate
How to Add a New Entity
Register the prefab in
GameplayAssetsConfig:
Extend the factory interface and implement the creation method in
GameFactory:
Request the factory via DI and create the object where needed:
Last updated