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 IInstantiator to 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 implementing IExitableState

  • Automatically 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 IInstantiator to instantiate objects (projectiles, enemies, upgrade parts, tentacles)

  • For UI elements such as DamagePopup or EnemyKillRewardText, uses standard Object.Instantiate


How to Add a New Entity

  1. Register the prefab in GameplayAssetsConfig:

  1. Extend the factory interface and implement the creation method in GameFactory:

  1. Request the factory via DI and create the object where needed:

Last updated