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

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)

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

ProPooling.Pool.Pool ( )

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

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

void ProPooling.Pool.AddPoolItems ( int  number)

Add the specified number of items to the pool

void ProPooling.Pool.ClearPool ( )

Clear all pooled items.

Any active instances will be first despawned before being destroyed.

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

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
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
void ProPooling.Pool.DespawnAll ( )

Despawn all items back to the queue.

Parameters
gameObject
Returns
void ProPooling.Pool.Initialise ( )

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

void ProPooling.Pool.Initialise ( MonoBehaviour  Owner)

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

bool ProPooling.Pool.IsSpawnedInstance ( PoolItem  poolItem)

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

Parameters
poolItem
Returns
bool ProPooling.Pool.IsSpawnedInstance ( GameObject  gameObject)

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

Parameters
poolItem
Returns
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
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
GameObject ProPooling.Pool.Spawn ( Vector3  position,
Quaternion  rotation,
Transform  parent = null 
)

Spawn a gameobject from the pool.

Parameters
position
rotation
parent
Returns
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 >.

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

Spawn a PoolItem from the pool.

Returns

Property Documentation

bool ProPooling.Pool.AddedToGlobalPools
getset

Returns whether this pool has been added to the GlobalPools

int ProPooling.Pool.Count
get

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

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

int ProPooling.Pool.ID
get

Returns the instance ID of the prefab associated with this pool

int ProPooling.Pool.InactiveCount
get

Returns the number of inactive items in this pool

int ProPooling.Pool.InitialSize
getset

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

bool ProPooling.Pool.IsInitialised
getset

Returns whether this pool has been initialised and pool items created

Transform ProPooling.Pool.ItemParent
getset

The parent transform under which pooled items will be held.

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

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

string ProPooling.Pool.Name
get

Returns the name of the prefab associated with this pool

GameObject ProPooling.Pool.Prefab
getset

The prefab / gameobject that we want to pool.

bool ProPooling.Pool.ProgressiveFill
getset

Whether to progressively fill the pool to the initial size.

int ProPooling.Pool.ProgressiveFillFrameInterval
getset

When progressively filling the frame interval between allocating new items.

int ProPooling.Pool.ProgressiveFillInitialAmount
getset

When progressively filling the number to initailly allocate.

int ProPooling.Pool.ProgressiveFillIntervalAmount
getset

When progressively filling the number to allocate each interval.

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)

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

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

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: