Class MonoBehaviourPool<T>
- Namespace
- Gamelogic.Extensions
- Assembly
- Assembly-CSharp.dll
A pool suitable for MonoBehaviour objects that can be instantiated from a given prefab.
public class MonoBehaviourPool<T> where T : MonoBehaviour
Type Parameters
T
- Inheritance
-
MonoBehaviourPool<T>
- Inherited Members
- Extension Methods
Constructors
MonoBehaviourPool(T, GameObject, int, Action<T>, Action<T>)
Initializes a new instance of the MonoBehaviourPool<T> class.
public MonoBehaviourPool(T prefab, GameObject parent, int initialCount, Action<T> wakeUp, Action<T> setToSleep)
Parameters
prefab
TThe prefab used to instantiate objects from.
parent
GameObjectThe parent object to which the pool objects will be attached.
initialCount
intThe initial count of objects to create.
wakeUp
Action<T>A function called on an object when it is woken up.
setToSleep
Action<T>A function called on objects when they are put to sleep.
Properties
IsObjectAvailable
Gets a value indicating whether a sleeping object is available.
public bool IsObjectAvailable { get; }
Property Value
- bool
true
if a sleeping object is available; otherwise,false
.
Methods
DecCapacity(int)
Decreases the capacity of the pool.
public void DecCapacity(int decrement)
Parameters
decrement
intThe number of pool objects to kill.
GetNewObject()
Gets a freshly awoken object from the pool.
public T GetNewObject()
Returns
- T
T.
IncCapacity(int)
Increases thew capacity of the pool.
public void IncCapacity(int increment)
Parameters
increment
intThe number of new pool objects to add.
ReleaseObject(T)
Releases the specified object back to the pool.
public void ReleaseObject(T obj)
Parameters
obj
T