![]() |
Infohazard.Core 1.4.1
Infohazard Core Utility Library
|
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... | |
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.
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.
key | Key used to spawn objects using handler. |
handler | IPoolHandler used to spawn objects for key. |
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.
void Infohazard.Core.PoolManager.DespawnInstance | ( | Spawnable | instance | ) |
Despawn the given instance, returning it back to its pool if it has one.
instance |
bool Infohazard.Core.PoolManager.HasPoolHandler | ( | object | key | ) |
Return whether a IPoolHandler has been registered with the given key.
key | Key of the IPoolHandler, such as the prefab itself. |
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.
key | Key of the IPoolHandler, such as the prefab itself. |
spawnParams | Additional spawn info. |
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.
prefab | The prefab to spawn. |
spawnParams | Additional spawn information. |
bool Infohazard.Core.PoolManager.TryGetPoolHandler | ( | object | key, |
out IPoolHandler | handler | ||
) |
Get the IPoolHandler for the given key, if one is registered (return false otherwise).
key | Key of the IPoolHandler, such as the prefab itself. |
handler | The registered IPoolHandler for key, or null if none. |
|
staticget |
The singleton PoolManager instance.
If this property is accessed when there is no active instance, one will be created automatically.
|
get |
Transform that inactive instances will be parented to.