GameObject Pooler
FreakLib.Pooling.PoolItem Class Reference

This class implements a single pool item for use with the Pool class. More...

Inheritance diagram for FreakLib.Pooling.PoolItem:

Public Types

enum  ResizeStrategy { DontResize, Linear, Exponential }
 Resize strategy. More...
 

Public Member Functions

void Instantiate ()
 Initialize this instance. More...
 
void Clear ()
 Clear this instance. More...
 
void SetObject (GameObject original, int capacity=1)
 Sets the original object. More...
 
GameObject Borrow ()
 Borrow from this instance. More...
 
void Return (GameObject obj)
 Returns the specified GameObject. More...
 
void Resize (int size, bool force=false)
 Resize the pool for this PoolItem. More...
 

Properties

GameObject PooledObject [get]
 Gets the original object. More...
 
int PooledObjectID [get]
 Gets the instance ID of the original object. More...
 
int PoolSize [get]
 Gets the size of the pool. More...
 
int FreeObjects [get]
 Gets the number of free objects. More...
 
int MaxBorrowed [get]
 Gets the max number of borrowed objects. More...
 
bool IsInstantiated [get]
 Gets a value indicating whether this instance is initialized. More...
 

Detailed Description

This class implements a single pool item for use with the Pool class.

You should not use this class directly yourself, but handle it through the Pool class, especially Borrow and Return which will cause errors in the pool if used directly from the PoolItem.

PoolItem is a MonoBehaviour and so needs to be placed on a GameObject. It should be a child of the Pool in the hierarchy, and will act as the parent for all pooled gameobjects of this type while they are inactive.

New instances of this class is normally generated by the Pool class, either in the inspector or at runtime.

Member Enumeration Documentation

Resize strategy.

Indicates a strategy for increasing and decreasing the number of items in a pool.

DontResize indicates no resizing should be done, Linear increases and decreases by a giver number, and Exponential will double/halve the number of items.

Member Function Documentation

GameObject FreakLib.Pooling.PoolItem.Borrow ( )

Borrow from this instance.

This should not be called directly, use Pool.Borrow instead. If you should need to use this yourself, you need to take care to Return the object to the same PoolItem instance.

void FreakLib.Pooling.PoolItem.Clear ( )

Clear this instance.

This will clear all the copies for this item.

void FreakLib.Pooling.PoolItem.Instantiate ( )

Initialize this instance.

This will instantiate the needed copies for the pool.

void FreakLib.Pooling.PoolItem.Resize ( int  size,
bool  force = false 
)

Resize the pool for this PoolItem.

This will set the number of copies to the specified size.

If the new size is lower than the current, and there are not enough free objects to reduce to this size, a PoolException will be thrown, unless the force parameter is set to true. In that case objects that have been borrowed will be destroyed.

Parameters
sizeThe new number of copies.
forceIf set to true borrowed objects will be destroyed if necessary to reduce to the new size.
void FreakLib.Pooling.PoolItem.Return ( GameObject  obj)

Returns the specified GameObject.

This should not be used directly, use Pool.Return instead.

Parameters
objThe GameObject to return.
void FreakLib.Pooling.PoolItem.SetObject ( GameObject  original,
int  capacity = 1 
)

Sets the original object.

This will clear the current copies and create a new pool of the new original object.

Parameters
originalOriginal GameObject.
capacityNumber of copies.

Property Documentation

int FreakLib.Pooling.PoolItem.FreeObjects
get

Gets the number of free objects.

The number of free objects.

bool FreakLib.Pooling.PoolItem.IsInstantiated
get

Gets a value indicating whether this instance is initialized.

true if this instance is initialized; otherwise, false.

int FreakLib.Pooling.PoolItem.MaxBorrowed
get

Gets the max number of borrowed objects.

The max number of borrowed.

GameObject FreakLib.Pooling.PoolItem.PooledObject
get

Gets the original object.

The original object.

int FreakLib.Pooling.PoolItem.PooledObjectID
get

Gets the instance ID of the original object.

The instance ID.

int FreakLib.Pooling.PoolItem.PoolSize
get

Gets the size of the pool.

The size of the pool.


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