Table of Contents

Constructor MonoBehaviourPool

Namespace
Gamelogic.Extensions
Assembly
Gamelogic.Extensions.dll

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 T

The prefab used to instantiate objects from.

parent GameObject

The parent object to which the pool objects will be attached. If null the object will be spawned without any parent.

initialCount int

The 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.

Remarks

The pool instantiates instances of the prefab to create new objects for the pool, for the first time in this constructor, and later when the pool is grown with IncreaseCapacity(int) or SetCapacity<T>(IPool<T>, int, bool).

The game objects of the instances are destroyed when the size of the pool is reduced with DecreaseCapacity(int, bool), SetCapacity<T>(IPool<T>, int, bool), or Clear<T>(IPool<T>, bool).