Pro Pooling
ProPooling.Pool Class Reference

Prefab pooling class that can preallocate a certain number of instances. More...

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

Public Types

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...
 

Public Member Functions

 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...
 
virtual PoolItem SpawnPoolItem (Transform parent=null)
 Spawn a PoolItem 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

virtual PoolItem CreatePoolItem ()
 Create a new PoolItem More...
 

Properties

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

Prefab pooling class that can preallocate a certain number of instances.

Member Enumeration Documentation

◆ MaximumSizeExceededModeType

The action to take when a pool item is requested and the maximum number of items allowed are all already in use

Enumerator
CreateNonPoolItems 

Create ad-hoc extra items on the fly that aren't returned to the pool

ReturnNull 

Return null

RecycleOldest 

Recycle (Reuse) the oldest item)

◆ SizeExceededModeType

The action to take when a pool item is requested and the pool is empty (all items are in use)

Enumerator
IncreasePoolSize 

Increase the pool size

CreateNonPoolItems 

Create ad-hoc extra items on the fly that aren't returned to the pool

ReturnNull 

Return null

RecycleOldest 

Recycle (Reuse) the oldest item)

Constructor & Destructor Documentation

◆ Pool() [1/2]

ProPooling.Pool.Pool ( )

Parameterless constructor to let us override and instantiate from within the pool editor

◆ Pool() [2/2]

ProPooling.Pool.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

Parameters
prefab
initialSize
sizeExceededMode
hasMaximumSize
maximumSize
itemParent

Member Function Documentation

◆ AddPoolItems()

void ProPooling.Pool.AddPoolItems ( int  number)

Add the specified number of items to the pool

◆ ClearPool()

void ProPooling.Pool.ClearPool ( )

Clear all pooled items.

Any active instances will be first despawned before being destroyed.

◆ CreatePoolItem()

virtual PoolItem ProPooling.Pool.CreatePoolItem ( )
protectedvirtual

Create a new PoolItem

Override this in subclasses if you want to use subclasses of PoolItem. See also PoolGeneric for a generic implementation of this

Returns

Reimplemented in ProPooling.PoolGeneric< T >.

◆ Despawn() [1/2]

bool ProPooling.Pool.Despawn ( PoolItem  poolItem)

Despawn an item back to the queue. If we are above the maximum capacity then we just delete the item.

Parameters
poolItem
Returns

◆ Despawn() [2/2]

bool ProPooling.Pool.Despawn ( GameObject  gameObject)

Despawn an item back to the queue. If we are above the maximum capacity then we just delete the item.

Parameters
gameObject
Returns

◆ DespawnAll()

void ProPooling.Pool.DespawnAll ( )

Despawn all items back to the queue.

Parameters
gameObject
Returns

◆ Initialise() [1/2]

void ProPooling.Pool.Initialise ( )

Create the specified number of instances in an inactive state and add to the inactive list.

◆ Initialise() [2/2]

void ProPooling.Pool.Initialise ( MonoBehaviour  Owner)

Create the specified number of instances in an inactive state and add to the inactive list.

◆ IsSpawnedInstance() [1/2]

bool ProPooling.Pool.IsSpawnedInstance ( PoolItem  poolItem)

Return whether the specified item is spawned and contained in the pool.

Parameters
poolItem
Returns

◆ IsSpawnedInstance() [2/2]

bool ProPooling.Pool.IsSpawnedInstance ( GameObject  gameObject)

Return whether the specified item is spawned and contained in the pool.

Parameters
poolItem
Returns

◆ PoolItemForGameObject()

PoolItem ProPooling.Pool.PoolItemForGameObject ( GameObject  gameObject)

Returns the PoolItem corresponding to the specified GameObject

Parameters
gameObject
Returns
PoolItem or null if the GameObject is not in the Pool

◆ Spawn() [1/2]

GameObject ProPooling.Pool.Spawn ( Transform  parent = null)

Spawn a gameobject from the pool.

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

Returns

◆ Spawn() [2/2]

GameObject ProPooling.Pool.Spawn ( Vector3  position,
Quaternion  rotation,
Transform  parent = null 
)

Spawn a gameobject from the pool.

Parameters
position
rotation
parent
Returns

◆ SpawnPoolItem() [1/2]

virtual PoolItem ProPooling.Pool.SpawnPoolItem ( Transform  parent = null)
virtual

Spawn a PoolItem from the pool.

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

Returns

Reimplemented in ProPooling.PoolGeneric< T >.

◆ SpawnPoolItem() [2/2]

PoolItem ProPooling.Pool.SpawnPoolItem ( Vector3  position,
Quaternion  rotation,
Transform  parent = null 
)

Spawn a PoolItem from the pool.

Returns

Property Documentation

◆ AddedToGlobalPools

bool ProPooling.Pool.AddedToGlobalPools
getset

Returns whether this pool has been added to the GlobalPools

◆ Count

int ProPooling.Pool.Count
get

Returns the total number of instances in this pool (both inactive and in use).

◆ HasMaximumSize

bool ProPooling.Pool.HasMaximumSize
getset

If the size can grow, then whether the pool has a maximum size to which it can grow (default false).

◆ ID

int ProPooling.Pool.ID
get

Returns the instance ID of the prefab associated with this pool

◆ InactiveCount

int ProPooling.Pool.InactiveCount
get

Returns the number of inactive items in this pool

◆ InitialSize

int ProPooling.Pool.InitialSize
getset

The initial number of pool items that should be created when this pool is loaded.

◆ IsInitialised

bool ProPooling.Pool.IsInitialised
getset

Returns whether this pool has been initialised and pool items created

◆ ItemParent

Transform ProPooling.Pool.ItemParent
getset

The parent transform under which pooled items will be held.

◆ MaximumSize

int ProPooling.Pool.MaximumSize
getset

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.")]

◆ MaximumSizeExceededMode

MaximumSizeExceededModeType ProPooling.Pool.MaximumSizeExceededMode
getset

The action to take when a pool item is requested and the maximum number of items allowed are all already in use

◆ Name

string ProPooling.Pool.Name
get

Returns the name of the prefab associated with this pool

◆ Prefab

GameObject ProPooling.Pool.Prefab
getset

The prefab / gameobject that we want to pool.

◆ ProgressiveFill

bool ProPooling.Pool.ProgressiveFill
getset

Whether to progressively fill the pool to the initial size.

◆ ProgressiveFillFrameInterval

int ProPooling.Pool.ProgressiveFillFrameInterval
getset

When progressively filling the frame interval between allocating new items.

◆ ProgressiveFillInitialAmount

int ProPooling.Pool.ProgressiveFillInitialAmount
getset

When progressively filling the number to initailly allocate.

◆ ProgressiveFillIntervalAmount

int ProPooling.Pool.ProgressiveFillIntervalAmount
getset

When progressively filling the number to allocate each interval.

◆ SizeExceededMode

SizeExceededModeType ProPooling.Pool.SizeExceededMode
getset

The action to take when a pool item is requested and the pool is empty (all items are in use)

◆ SpawnedAndNonPoolCount

int ProPooling.Pool.SpawnedAndNonPoolCount
getset

Returns the number of spawned (in use) instances from this pool plus any non pool items that have been allocated

◆ SpawnedAndNonPoolCountMaximum

int ProPooling.Pool.SpawnedAndNonPoolCountMaximum
getset

Returns the maximum number of spawned (in use instances from this pool plus any non pool items that have been allocated

◆ SpawnedCount

int ProPooling.Pool.SpawnedCount
get

Returns the number of spawned (in use) instances from this pool


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