Class PrefabPoolManager
- Namespace
- TAsset
Bundle .Extensions
- Assembly
- TAssetBundle.Extensions.dll
A class responsible for managing Prefab
- Inheritance
-
Prefab
Pool Manager
- Inherited Members
Properties
PrefabPoolRoot
Gets the root transform for all prefab pools. Pooled objects will be parented under this transform to maintain a clean hierarchy in the scene.
Property Value
- Transform
PrefabPools
Gets the dictionary that holds the prefab pools for each prefab. This allows access to the pools for managing the reuse of instantiated prefabs.
Property Value
- Dictionary<Game
Object , PrefabPool >
Methods
Clear()
Clears and destroys all prefab pools. This should be used when transitioning between scenes or when clearing unused assets.
Clear(GameObject)
Clears and destroys the prefab pool for the given prefab. This should be used if a specific prefab is no longer needed in the scene.
Parameters
prefab
GameObject The prefab to clear the pool for.
Clear<T>(T)
Clears and destroys the prefab pool for the given prefab type.
Parameters
prefab
TThe prefab to clear the pool for.
Type Parameters
T
The type of the prefab.
Get(GameObject, Transform, bool)
Retrieves an object from the pool for the given prefab, or creates one if none exist.
If the prefab is not loaded yet, consider using Get
Parameters
prefab
GameObject The prefab to get the object for.
parent
TransformThe parent transform for the created object. Defaults to
null
.active
boolWhether the object should be active when created. Defaults to
true
.
Returns
- Game
Object The retrieved or created object.
GetPool(GameObject)
Retrieves the prefab pool for the given prefab, creating one if none exist.
If the prefab is dynamically loaded via Asset
Parameters
prefab
GameObject The prefab to get the pool for.
Returns
- Prefab
Pool The prefab pool for the given prefab.
GetPoolObjectCount(GameObject)
Gets the number of objects in the pool for the given prefab.
Parameters
prefab
GameObject The prefab to get the object count for.
Returns
- int
The number of objects in the pool.
Get<T>(T, Transform, bool)
Retrieves an object of type T
from the pool for the given prefab, or creates one if none exist.
Parameters
prefab
TThe prefab to get the object for.
parent
TransformThe parent transform for the created object. Defaults to
null
.active
boolWhether the object should be active when created. Defaults to
true
.
Returns
- T
The retrieved or created object of type
T
.
Type Parameters
T
The type of the prefab.
Reserve(GameObject, int)
Reserves a specified number of objects for the given prefab in the pool. This can help reduce instantiation overhead when expecting a large number of object spawns.
Parameters
prefab
GameObject The prefab to reserve objects for.
count
intThe number of objects to reserve.
Reserve<T>(T, int)
Reserves a specified number of objects for the given prefab type in the pool.
Parameters
prefab
TThe prefab to reserve objects for.
count
intThe number of objects to reserve.
Type Parameters
T
The type of the prefab.
TryGetPool(GameObject, out PrefabPool)
Attempts to get the pool for the given prefab. Returns false if no pool exists.
Parameters
prefab
GameObject The prefab to get the pool for.
prefabPool
PrefabPool The prefab pool for the given prefab.
Returns
- bool
True if the pool was found, otherwise false.