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.
It also resolves authored content to the key a character was registered under
(ICharacterKeyResolver), so a wave entry naming an actor prefab spawns the registered
character whose config names that prefab. And it tells a caller, with every spawn, whether a refusal was
already reported (IReportingCharacterSpawner), so a wave that forfeits a refused actor does not
report the same cause again.
Inheritance
UnityCharacterPoolService
Assembly: Serenity.UnityCharacter.Infrastructure.dll
Syntax
public class UnityCharacterPoolService : MonoBehaviour, ICharacterSpawnService, IService, IFoundationSettings, ICharacterKeyResolver, IReportingCharacterSpawner
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
_guid
Declaration
Field Value
_id
Declaration
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
Guid
Declaration
public string Guid { get; set; }
Property Value
Id
Declaration
public string Id { get; set; }
Property Value
LogService
Declaration
public ILogService LogService { get; set; }
Property Value
Methods
GetOrCreateInstance(ICharacterConfig)
Hands out a pooled instance of archetype, reusing an inactive one or
instantiating its prefab; null, with the same report Spawn(string, float, float, float, float, float, float, float) writes, when the prefab is missing
or has no Character View.
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
TryResolveCharacterKey(object, out string)
Declaration
public bool TryResolveCharacterKey(object authoredCharacter, out string characterKey)
Parameters
| Type |
Name |
Description |
| object |
authoredCharacter |
|
| string |
characterKey |
|
Returns
TrySpawn(string, float, float, float, float, float, float, float)
Declaration
public CharacterSpawnAttempt TrySpawn(string characterKey, float positionX, float positionY, float positionZ, float rotationX, float rotationY, float rotationZ, float rotationW)
Parameters
Returns
Implements