Class Pool<T>
- Namespace
- Gamelogic.Extensions
- Assembly
- Assembly-CSharp.dll
A light-weight pool class. Can be used out of the box, or as base for more sophisticated pools.
public class Pool<T> where T : class
Type Parameters
TThe type of the objects to pool.
- Inheritance
-
Pool<T>
- Inherited Members
- Extension Methods
Constructors
Pool(int, Func<T>, Action<T>, Action<T>, Action<T>)
Initializes a new instance of the Pool<T> class.
public Pool(int initialCount, Func<T> create, Action<T> kill, Action<T> wakeUp, Action<T> setToSleep)
Parameters
initialCountintThe initial number of objects to create.
createFunc<T>A function that creates a new object of type T.
killAction<T>The function that destroys an object of type T.
wakeUpAction<T>A function called when an object is woken up.
setToSleepAction<T>A function called when an object is set to sleep.
Properties
Capacity
The number total objects in the pool (awake and asleep).
public int Capacity { get; }
Property Value
- int
The capacity.
IsObjectAvailable
Returns whether there is a sleeping object available.
public bool IsObjectAvailable { get; }
Property Value
- bool
trueif this a sleeping object is available; otherwise,false.
Methods
DecCapacity(int)
Decreases the capacity of the pool.
public void DecCapacity(int decrement)
Parameters
decrementintThe number of pool objects to kill.
GetNewObject()
Gets a new object from the pool.
public T GetNewObject()
Returns
- T
A freshly awakened object.
Exceptions
- InvalidOperationException
No items in pool
IncCapacity(int)
Increases thew capacity of the pool.
public void IncCapacity(int increment)
Parameters
incrementintThe number of new pool objects to add.
Release(T)
Releases the specified object back to the pool.
public void Release(T obj)
Parameters
objTThe object to release.