Constructor Pool
- Namespace
- Gamelogic.Extensions
- Assembly
- Gamelogic.Extensions.dll
Pool(int, Func<T>, Action<T>, Action<T>, Action<T>)
Initializes a new instance of the Pool<T> class.
public Pool(int initialCapacity, Func<T> create, Action<T> destroy, Action<T> activate, Action<T> deactivate)
Parameters
initialCapacityintThe initial capacity of the pool, that is, how many object to create.
createFunc<T>A function that creates a new object of type
T. This should create objects in the active state; they will be deactivated by the pool. This function should (ideally) also instantiate everything the class will need, and do any tasks that do not be repeated each time the object is made active.destroyAction<T>The action that destroys an object of type
T. If it is an ordinary C# object, you do not need to provide a destroy method — references to the object from this object will be removed, and (provided you do not have references to it somewhere too), it will be released naturally like any C# object. IfTis a Unity Object, or a Component whose UnityEngine.Component.gameObject you want to be destroyed, this action should do that. Also consider using the MonoBehaviourPool<T> class instead. This action is called by methods that allow you to specify whether to deactivate objects first, so this action need not do any tasks that are already done bydeactivateaction.activateAction<T>A function called when an object is activated, when it is acquired.
deactivateAction<T>A function called when an object is deactivated, either when releasing it, or when it is created for the first time. If your objects accumulate references to other objects while active, and those references cannot be re-used, remove them in this action so that those objects do not hog memory while inactive.
Exceptions
- ArgumentOutOfRangeException
initialCapacityis negative.- ArgumentNullException
createis null.