Infohazard.Core 1.4.1
Infohazard Core Utility Library
Loading...
Searching...
No Matches
Infohazard.Core.PoolManager Class Reference

The singleton manager class that handles object pooling. More...

Public Member Functions

Spawnable SpawnPrefab (Spawnable prefab, in SpawnParams spawnParams=default)
 Spawn an instance of the specified prefab, creating a DefaultPoolHandler if one does not already exist. More...
 
Spawnable SpawnFromKey (object key, in SpawnParams spawnParams=default)
 Spawn an instance with the specified key. If no IPoolHandler is registered for key, an error is logged and null is returned. More...
 
bool HasPoolHandler (object key)
 Return whether a IPoolHandler has been registered with the given key. More...
 
bool TryGetPoolHandler (object key, out IPoolHandler handler)
 Get the IPoolHandler for the given key, if one is registered (return false otherwise). More...
 
void AddPoolHandler (object key, IPoolHandler handler)
 Register a new IPoolHandler for the given key. More...
 
void DespawnInstance (Spawnable instance)
 Despawn the given instance, returning it back to its pool if it has one. More...
 
void ClearInactiveObjects ()
 Destroy and cleanup any inactive instances for DefaultPoolHandlers created by the PoolManager. More...
 

Properties

static PoolManager Instance [get]
 The singleton PoolManager instance. More...
 
Transform PoolTransform [get]
 Transform that inactive instances will be parented to. More...
 

Detailed Description

The singleton manager class that handles object pooling.

There should only ever be on PoolManager at a time, but this can be created either manually or automatically when needed. You can have one PoolManager per scene, or have a shared one across all scenes. The only time you'll typically need to interact with the PoolManager is to call ClearInactiveObjects when loading a new level, if the previously pooled objects are no longer necessary. All normal spawning and despawning of instances should be done through the Spawnable class.

Member Function Documentation

◆ AddPoolHandler()

void Infohazard.Core.PoolManager.AddPoolHandler ( object  key,
IPoolHandler  handler 
)

Register a new IPoolHandler for the given key.

The registered IPoolHandler will NOT be retained by the PoolManager.

Parameters
keyKey used to spawn objects using handler.
handlerIPoolHandler used to spawn objects for key.

◆ ClearInactiveObjects()

void Infohazard.Core.PoolManager.ClearInactiveObjects ( )

Destroy and cleanup any inactive instances for DefaultPoolHandlers created by the PoolManager.

IPoolHandlers created manually and added using AddPoolHandler will NOT be affected. This is meant to be called when loading a new level, to ensure pooled instances to not stay around forever.

◆ DespawnInstance()

void Infohazard.Core.PoolManager.DespawnInstance ( Spawnable  instance)

Despawn the given instance, returning it back to its pool if it has one.

Parameters
instance

◆ HasPoolHandler()

bool Infohazard.Core.PoolManager.HasPoolHandler ( object  key)

Return whether a IPoolHandler has been registered with the given key.

Parameters
keyKey of the IPoolHandler, such as the prefab itself.
Returns
Whether there is an IPoolHandler for key.

◆ SpawnFromKey()

Spawnable Infohazard.Core.PoolManager.SpawnFromKey ( object  key,
in SpawnParams  spawnParams = default 
)

Spawn an instance with the specified key. If no IPoolHandler is registered for key, an error is logged and null is returned.

The key may be a prefab that was previously registered using SpawnPrefab, or another object for which an IPoolHandler was manually registered using AddPoolHandler.

Parameters
keyKey of the IPoolHandler, such as the prefab itself.
spawnParamsAdditional spawn info.
Returns
The spawned instance, or null if no handler found.

◆ SpawnPrefab()

Spawnable Infohazard.Core.PoolManager.SpawnPrefab ( Spawnable  prefab,
in SpawnParams  spawnParams = default 
)

Spawn an instance of the specified prefab, creating a DefaultPoolHandler if one does not already exist.

If a new DefaultPoolHandler is created, it will be retained by the PoolManager.

Parameters
prefabThe prefab to spawn.
spawnParamsAdditional spawn information.
Returns
The spawned instance.

◆ TryGetPoolHandler()

bool Infohazard.Core.PoolManager.TryGetPoolHandler ( object  key,
out IPoolHandler  handler 
)

Get the IPoolHandler for the given key, if one is registered (return false otherwise).

Parameters
keyKey of the IPoolHandler, such as the prefab itself.
handlerThe registered IPoolHandler for key, or null if none.
Returns
Whether there is an IPoolHandler for key.

Property Documentation

◆ Instance

PoolManager Infohazard.Core.PoolManager.Instance
staticget

The singleton PoolManager instance.

If this property is accessed when there is no active instance, one will be created automatically.

◆ PoolTransform

Transform Infohazard.Core.PoolManager.PoolTransform
get

Transform that inactive instances will be parented to.


The documentation for this class was generated from the following file: