Class UnityCharacterPoolService
Unity implementation of ICharacterSpawnService for characters.
Owns all character pooling, instantiation, and GameObject lifecycle.
Uses injected delegates for ViewModel binding to avoid circular assembly
dependencies with InterfaceAdapters. Delegates receive Application-layer
ICharacterConfig — no Infrastructure types leak into the bind contract.
Per architecture Rule 3.3: Character module owns instantiation/pooling.
Inheritance
UnityCharacterPoolService
Assembly: Serenity.UnityCharacter.Infrastructure.dll
Syntax
public class UnityCharacterPoolService : MonoBehaviour, ICharacterSpawnService
Constructors
UnityCharacterPoolService()
Declaration
public UnityCharacterPoolService()
Fields
_activeById
Maps CharacterId → PooledCharacter for fast lookup on Release.
Declaration
protected readonly Dictionary<string, UnityCharacterPoolService.PooledCharacter> _activeById
Field Value
_bind
Declaration
protected UnityCharacterPoolService.BindDelegate _bind
Field Value
_logService
Declaration
protected ILogService _logService
Field Value
_pool
Pool buckets keyed by prefab GetInstanceID().
Each bucket holds all instances ever created from that prefab.
Declaration
protected readonly Dictionary<int, List<UnityCharacterPoolService.PooledCharacter>> _pool
Field Value
_rebind
Declaration
protected UnityCharacterPoolService.RebindDelegate _rebind
Field Value
_registeredCharacters
Maps archetype key string → registered ICharacterConfig.
Declaration
protected readonly Dictionary<string, ICharacterConfig> _registeredCharacters
Field Value
_unbind
Declaration
protected UnityCharacterPoolService.UnbindDelegate _unbind
Field Value
Properties
ActiveCount
Declaration
public int ActiveCount { get; }
Property Value
Methods
GetOrCreateInstance(ICharacterConfig)
Declaration
protected UnityCharacterPoolService.PooledCharacter GetOrCreateInstance(ICharacterConfig archetype)
Parameters
Returns
Initialize(ILogService, BindDelegate, RebindDelegate, UnbindDelegate)
Initializes the pool service with required dependencies.
Binding delegates are provided by the installer to avoid circular
assembly dependencies between Infrastructure and InterfaceAdapters.
Declaration
public void Initialize(ILogService logService, UnityCharacterPoolService.BindDelegate bind, UnityCharacterPoolService.RebindDelegate rebind, UnityCharacterPoolService.UnbindDelegate unbind)
Parameters
OnDestroy()
Declaration
protected void OnDestroy()
RegisterCharacters(string, ICharacterConfig)
Registers a character config so the pool knows which prefab to use
for the given character key. Must be called before Spawn for that key.
Declaration
public void RegisterCharacters(string archetypeKey, ICharacterConfig config)
Parameters
Release(CharacterId)
Declaration
public void Release(CharacterId characterId)
Parameters
ReleaseAll()
Declaration
ReleaseInstance(PooledCharacter)
Declaration
protected void ReleaseInstance(UnityCharacterPoolService.PooledCharacter pooled)
Parameters
Spawn(string, float, float, float, float, float, float, float)
Declaration
public CharacterId Spawn(string archetypeKey, float posX, float posY, float posZ, float rotX, float rotY, float rotZ, float rotW)
Parameters
Returns
Implements