Infohazard.Core 1.4.1
Infohazard Core Utility Library
Loading...
Searching...
No Matches
Infohazard.Core.Pool< T > Class Template Reference

Provides a simple pool with an interface similar to the official Unity pool added in 2021. More...

Public Member Functions

 Pool (Func< T > createFunc, Action< T > getAction=null, Action< T > releaseAction=null, Action< T > destroyAction=null, int maxCount=0)
 Create a new ObjectPool. More...
 
Get ()
 Retrieve an item from the pool, creating a new one if necessary. More...
 
void Release (T item)
 Return an object to the pool, destroying it if over max count. More...
 
void Clear ()
 Destroy all objects in the pool. More...
 
void Remove (T item)
 Remove an item from the pool without cleaning it up. More...
 
void Dispose ()
 Destroy all objects in the pool. More...
 

Properties

Func< T > CreateFunc [get, set]
 Function invoked to create an instance, which must not be null. More...
 
Action< T > GetAction [get, set]
 Callback invoked when an object is retrieved from the pool. More...
 
Action< T > ReleaseAction [get, set]
 Callback invoked when an object is returned to the pool. More...
 
Action< T > DestroyAction [get, set]
 Callback invoked when an object is destroyed in the pool. More...
 
int MaxCount = 0 [get, set]
 Max objects in pool, or 0 for no limit. More...
 

Detailed Description

Provides a simple pool with an interface similar to the official Unity pool added in 2021.

Template Parameters
TType of pooled object.

Constructor & Destructor Documentation

◆ Pool()

Infohazard.Core.Pool< T >.Pool ( Func< T >  createFunc,
Action< T >  getAction = null,
Action< T >  releaseAction = null,
Action< T >  destroyAction = null,
int  maxCount = 0 
)

Create a new ObjectPool.

Parameters
createFuncFunction invoked to create an instance, which must not be null.
getActionCallback invoked when an object is retrieved from the pool.
releaseActionCallback invoked when an object is returned to the pool.
destroyActionCallback invoked when an object is destroyed in the pool.
maxCountMax objects in pool, or 0 for no limit.

Member Function Documentation

◆ Clear()

void Infohazard.Core.Pool< T >.Clear ( )

Destroy all objects in the pool.

◆ Dispose()

void Infohazard.Core.Pool< T >.Dispose ( )

Destroy all objects in the pool.

◆ Get()

T Infohazard.Core.Pool< T >.Get ( )

Retrieve an item from the pool, creating a new one if necessary.

Returns
The retrieved object.

◆ Release()

void Infohazard.Core.Pool< T >.Release ( item)

Return an object to the pool, destroying it if over max count.

Parameters
itemThe object to release.

◆ Remove()

void Infohazard.Core.Pool< T >.Remove ( item)

Remove an item from the pool without cleaning it up.

Parameters
itemItem to remove.

Property Documentation

◆ CreateFunc

Func<T> Infohazard.Core.Pool< T >.CreateFunc
getset

Function invoked to create an instance, which must not be null.

◆ DestroyAction

Action<T> Infohazard.Core.Pool< T >.DestroyAction
getset

Callback invoked when an object is destroyed in the pool.

◆ GetAction

Action<T> Infohazard.Core.Pool< T >.GetAction
getset

Callback invoked when an object is retrieved from the pool.

◆ MaxCount

int Infohazard.Core.Pool< T >.MaxCount = 0
getset

Max objects in pool, or 0 for no limit.

◆ ReleaseAction

Action<T> Infohazard.Core.Pool< T >.ReleaseAction
getset

Callback invoked when an object is returned to the pool.


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