Pro Pooling
ProPooling.PoolGeneric< T > Class Template Reference

A generic implementation of the Pooling class that can be used to easily handle custom PoolItem types. By specifying your own type you can add additional customisation during setup, deallocation and otherwise. More...

Inheritance diagram for ProPooling.PoolGeneric< T >:
ProPooling.Pool

Public Member Functions

 PoolGeneric (GameObject prefab, int initialSize=10, Transform inactiveParent=null)
 Constructor for a basic pool with no maximum size More...
 
 PoolGeneric (GameObject prefab, int initialSize, SizeExceededModeType limitExceededMode, bool hasMaximumSize, int maximumSize, MaximumSizeExceededModeType maximumSizeExceededModeType, Transform inactiveParent=null)
 Constructor for creating a pool instance More...
 
new T SpawnPoolItem (Transform parent=null)
 Spawn an item from the pool, optionally creating a new one if there aren't already enough avilable. More...
 
new T SpawnPoolItem (Vector3 position, Quaternion rotation, Transform parent=null)
 Spawn an item from the pool, optionally creating a new one if there aren't already enough avilable. More...
 
- Public Member Functions inherited from ProPooling.Pool
 Pool ()
 Parameterless constructor to let us override and instantiate from within the pool editor More...
 
 Pool (GameObject prefab, int initialSize=0, SizeExceededModeType sizeExceededMode=SizeExceededModeType.IncreasePoolSize, bool hasMaximumSize=false, int maximumSize=0, MaximumSizeExceededModeType maximumSizeExceededMode=MaximumSizeExceededModeType.ReturnNull, Transform itemParent=null)
 Constructor for creating a pool instance More...
 
void Initialise ()
 Create the specified number of instances in an inactive state and add to the inactive list. More...
 
void Initialise (MonoBehaviour Owner)
 Create the specified number of instances in an inactive state and add to the inactive list. More...
 
void AddPoolItems (int number)
 Add the specified number of items to the pool More...
 
void ClearPool ()
 Clear all pooled items. More...
 
PoolItem PoolItemForGameObject (GameObject gameObject)
 Returns the PoolItem corresponding to the specified GameObject More...
 
bool IsSpawnedInstance (PoolItem poolItem)
 Return whether the specified item is spawned and contained in the pool. More...
 
bool IsSpawnedInstance (GameObject gameObject)
 Return whether the specified item is spawned and contained in the pool. More...
 
GameObject Spawn (Transform parent=null)
 Spawn a gameobject from the pool. More...
 
GameObject Spawn (Vector3 position, Quaternion rotation, Transform parent=null)
 Spawn a gameobject from the pool. More...
 
PoolItem SpawnPoolItem (Vector3 position, Quaternion rotation, Transform parent=null)
 Spawn a PoolItem from the pool. More...
 
bool Despawn (PoolItem poolItem)
 Despawn an item back to the queue. If we are above the maximum capacity then we just delete the item. More...
 
bool Despawn (GameObject gameObject)
 Despawn an item back to the queue. If we are above the maximum capacity then we just delete the item. More...
 
void DespawnAll ()
 Despawn all items back to the queue. More...
 

Protected Member Functions

override PoolItem CreatePoolItem ()
 Create a new PoolItem of the generic typs More...
 

Additional Inherited Members

- Public Types inherited from ProPooling.Pool
enum  SizeExceededModeType { SizeExceededModeType.IncreasePoolSize, SizeExceededModeType.CreateNonPoolItems, SizeExceededModeType.ReturnNull, SizeExceededModeType.RecycleOldest }
 The action to take when a pool item is requested and the pool is empty (all items are in use) More...
 
enum  MaximumSizeExceededModeType { MaximumSizeExceededModeType.CreateNonPoolItems, MaximumSizeExceededModeType.ReturnNull, MaximumSizeExceededModeType.RecycleOldest }
 The action to take when a pool item is requested and the maximum number of items allowed are all already in use More...
 
- Properties inherited from ProPooling.Pool
GameObject Prefab [get, set]
 The prefab / gameobject that we want to pool. More...
 
int InitialSize [get, set]
 The initial number of pool items that should be created when this pool is loaded. More...
 
bool ProgressiveFill [get, set]
 Whether to progressively fill the pool to the initial size. More...
 
int ProgressiveFillInitialAmount [get, set]
 When progressively filling the number to initailly allocate. More...
 
int ProgressiveFillFrameInterval [get, set]
 When progressively filling the frame interval between allocating new items. More...
 
int ProgressiveFillIntervalAmount [get, set]
 When progressively filling the number to allocate each interval. More...
 
SizeExceededModeType SizeExceededMode [get, set]
 The action to take when a pool item is requested and the pool is empty (all items are in use) More...
 
bool HasMaximumSize [get, set]
 If the size can grow, then whether the pool has a maximum size to which it can grow (default false). More...
 
int MaximumSize [get, set]
 The maximum size of this pool. More items can be created on the fly if needed by enabling createIfMaximumExceeded but they won't be pooled.")] More...
 
MaximumSizeExceededModeType MaximumSizeExceededMode [get, set]
 The action to take when a pool item is requested and the maximum number of items allowed are all already in use More...
 
Transform ItemParent [get, set]
 The parent transform under which pooled items will be held. More...
 
int Count [get]
 Returns the total number of instances in this pool (both inactive and in use). More...
 
int InactiveCount [get]
 Returns the number of inactive items in this pool More...
 
int SpawnedCount [get]
 Returns the number of spawned (in use) instances from this pool More...
 
int SpawnedAndNonPoolCount [get, set]
 Returns the number of spawned (in use) instances from this pool plus any non pool items that have been allocated More...
 
int SpawnedAndNonPoolCountMaximum [get, set]
 Returns the maximum number of spawned (in use instances from this pool plus any non pool items that have been allocated More...
 
int ID [get]
 Returns the instance ID of the prefab associated with this pool More...
 
string Name [get]
 Returns the name of the prefab associated with this pool More...
 
bool AddedToGlobalPools [get, set]
 Returns whether this pool has been added to the GlobalPools More...
 
bool IsInitialised [get, set]
 Returns whether this pool has been initialised and pool items created More...
 

Detailed Description

A generic implementation of the Pooling class that can be used to easily handle custom PoolItem types. By specifying your own type you can add additional customisation during setup, deallocation and otherwise.

Type Constraints
T :PoolItem 
T :new() 

Constructor & Destructor Documentation

◆ PoolGeneric() [1/2]

ProPooling.PoolGeneric< T >.PoolGeneric ( GameObject  prefab,
int  initialSize = 10,
Transform  inactiveParent = null 
)

Constructor for a basic pool with no maximum size

Parameters
prefab
initialSize
inactiveParent

◆ PoolGeneric() [2/2]

ProPooling.PoolGeneric< T >.PoolGeneric ( GameObject  prefab,
int  initialSize,
SizeExceededModeType  limitExceededMode,
bool  hasMaximumSize,
int  maximumSize,
MaximumSizeExceededModeType  maximumSizeExceededModeType,
Transform  inactiveParent = null 
)

Constructor for creating a pool instance

Parameters
prefab
initialSize
sizeCanGrow
hasMaximumSize
maximumSize
createIfMaximumExceeded
inactiveParent

Member Function Documentation

◆ CreatePoolItem()

override PoolItem ProPooling.PoolGeneric< T >.CreatePoolItem ( )
protectedvirtual

Create a new PoolItem of the generic typs

Returns

Reimplemented from ProPooling.Pool.

◆ SpawnPoolItem() [1/2]

new T ProPooling.PoolGeneric< T >.SpawnPoolItem ( Transform  parent = null)
virtual

Spawn an item from the pool, optionally creating a new one if there aren't already enough avilable.

Position and rotation will be set to the default values that the initial prefab had.

Returns

Reimplemented from ProPooling.Pool.

◆ SpawnPoolItem() [2/2]

new T ProPooling.PoolGeneric< T >.SpawnPoolItem ( Vector3  position,
Quaternion  rotation,
Transform  parent = null 
)

Spawn an item from the pool, optionally creating a new one if there aren't already enough avilable.

Returns

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