Twoorb Plugins  1.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties
Twoorb.Utilities.ObjectPool< T > Class Template Reference

An object pool for classes derived from MonoBehaviour. Useful for optimization. The pool takes care of the instantiation of the original object and expands the pool if necessary. After you've created the pool, use FetchObject() to get an object and RecycleObject to give it back when you are done. More...

Public Member Functions

 ObjectPool (T sourceObject, int expandSizeStep=10, Transform disabledObjectParent=null)
 Creates an object pool with a MonoBehaviour as a base class. The object pool expands and instantiates the game object when it's necessary. More...
 
void DestroyObjects ()
 Clears the object stack and calls GameObject.Destroy() on each one. More...
 
FetchObject (Transform parent=null)
 Gets an instantiated object of the pool. More...
 
bool RecycleObject (T poolObject)
 Returns an object to the pool. More...
 

Properties

List< T > ActiveObjects [get]
 Active objects that are not recycled More...
 

Detailed Description

An object pool for classes derived from MonoBehaviour. Useful for optimization. The pool takes care of the instantiation of the original object and expands the pool if necessary. After you've created the pool, use FetchObject() to get an object and RecycleObject to give it back when you are done.

Template Parameters
TThe class to add to the pool. Needs to be derived from MonoBehaviour
Type Constraints
T :MonoBehaviour 

Constructor & Destructor Documentation

Twoorb.Utilities.ObjectPool< T >.ObjectPool ( sourceObject,
int  expandSizeStep = 10,
Transform  disabledObjectParent = null 
)

Creates an object pool with a MonoBehaviour as a base class. The object pool expands and instantiates the game object when it's necessary.

Parameters
sourceObjectThe original object to pool.
expandSizeStepHow many objects to expand the pool with when the pool is out of objects.
disabledObjectParentA parent to the disabled object for easier grouping

Member Function Documentation

void Twoorb.Utilities.ObjectPool< T >.DestroyObjects ( )

Clears the object stack and calls GameObject.Destroy() on each one.

T Twoorb.Utilities.ObjectPool< T >.FetchObject ( Transform  parent = null)

Gets an instantiated object of the pool.

Parameters
parentSets the parent transform for the instantiated object.
Returns
The instantiated object
bool Twoorb.Utilities.ObjectPool< T >.RecycleObject ( poolObject)

Returns an object to the pool.

Parameters
poolObject
Returns
Returns true on successful recycling

Property Documentation

List<T> Twoorb.Utilities.ObjectPool< T >.ActiveObjects
get

Active objects that are not recycled


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