NikosAssets.Pooling 0.1.0
Loading...
Searching...
No Matches
NikosAssets.Pooling.PoolContainer< TPoolItem > Class Template Reference

Basic implementation of the IPoolContainer More...

Public Member Functions

 PoolContainer ()
 PoolContainer (TPoolItem prefab)
virtual void Dispose ()
TPoolItem ReuseOrSpawnPoolItem (TPoolItem prefab, Transform parent, Predicate< TPoolItem > match=null)
 Pool or instantiate a new poolitem depending if any are free to use. Does not add the poolitem automatically to this container!
TPoolItem ReuseOrSpawnPoolItem (Transform parent, Predicate< TPoolItem > match=null)
 Pool or instantiate a new poolitem depending if any are free to use.
bool TryReusePoolItem (out TPoolItem poolItem, Predicate< TPoolItem > match=null)
 Gets a poolitem if any free are available.
List< TPoolItem > ReusePoolItems (Predicate< TPoolItem > match=null)
 Get as many pooled items that can be used as possible (does not instantiate new ones)
virtual void AddItem (TPoolItem item)
 Add a poolitem to this container (will automatically be removed when the item gets destroyed)
virtual bool RemoveItem (TPoolItem item)
 Remove the poolitem from this container.
void RemoveItem (int index)
 Remove the poolitem from this container by index.

Protected Member Functions

virtual void OnPoolItemDestroyed (IPoolItem poolItem)

Protected Attributes

List< TPoolItem > _poolList = new List<TPoolItem>()

Properties

List< TPoolItem > PoolList [get]
TPoolItem Prefab [get, set]
 The prefab to spawn if no poolable (free) item exists.

Detailed Description

Basic implementation of the IPoolContainer

Template Parameters
TPoolItem
Type Constraints
TPoolItem :Component 
TPoolItem :IPoolItem 

Member Function Documentation

◆ AddItem()

virtual void NikosAssets.Pooling.PoolContainer< TPoolItem >.AddItem ( TPoolItem item)
virtual

Add a poolitem to this container (will automatically be removed when the item gets destroyed)

Parameters
item

◆ RemoveItem() [1/2]

void NikosAssets.Pooling.PoolContainer< TPoolItem >.RemoveItem ( int index)

Remove the poolitem from this container by index.

Parameters
index

◆ RemoveItem() [2/2]

virtual bool NikosAssets.Pooling.PoolContainer< TPoolItem >.RemoveItem ( TPoolItem item)
virtual

Remove the poolitem from this container.

Parameters
item
Returns

◆ ReuseOrSpawnPoolItem() [1/2]

TPoolItem NikosAssets.Pooling.PoolContainer< TPoolItem >.ReuseOrSpawnPoolItem ( TPoolItem prefab,
Transform parent,
Predicate< TPoolItem > match = null )

Pool or instantiate a new poolitem depending if any are free to use. Does not add the poolitem automatically to this container!

Parameters
prefab
parent
matchOptional function to check for more conditions on poolable items
Returns
A poolitem where the PoolingReset() function has already been called on a pooled one only

◆ ReuseOrSpawnPoolItem() [2/2]

TPoolItem NikosAssets.Pooling.PoolContainer< TPoolItem >.ReuseOrSpawnPoolItem ( Transform parent,
Predicate< TPoolItem > match = null )

Pool or instantiate a new poolitem depending if any are free to use.

Parameters
parent
matchOptional function to check for more conditions on poolable items
Returns
A poolitem where the PoolingReset() function has already been called on a pooled one only

◆ ReusePoolItems()

List< TPoolItem > NikosAssets.Pooling.PoolContainer< TPoolItem >.ReusePoolItems ( Predicate< TPoolItem > match = null)

Get as many pooled items that can be used as possible (does not instantiate new ones)

Parameters
match
Returns

◆ TryReusePoolItem()

bool NikosAssets.Pooling.PoolContainer< TPoolItem >.TryReusePoolItem ( out TPoolItem poolItem,
Predicate< TPoolItem > match = null )

Gets a poolitem if any free are available.

Parameters
poolItemnull if no poolable item has been found
matchOptional function to check for more conditions on poolable items
Returns
true if a poolable item has been found and pooled out

The documentation for this class was generated from the following file:
  • PoolContainer.cs