-
Notifications
You must be signed in to change notification settings - Fork 3
Documentation
How to setup UnityObjectPooler in your Unity project?
Add ObjectPool.cs to your project assets folder.
Use the ObjectPool's static methods
ObjectPool can be accessed at all times.
ObjectPool.Clear();
// Clears the pool (should be used on scene reload or new scene load because its static)
ObjectPool.Add(poolable);
// Takes any Unity Component type
ObjectPool.Add<yourtype>(poolable);
// Same as non generic Add but a base class can be used when poolable is a subclass.
For example when you have:
public class Base { }
public class Derived : Base { }
ObjectPool.Add<Base>(poolable);
poolable is of type Derived, but you can also retrieve it like Get<Base>();
ObjectPool.Get<yourtype>();
// Will return one of your type from the pool (null if none in the pool)
ObjectPool.GetCustom<yourtype>(f => f.Score == 5);
// This will return your Component to the type passed if one is found based on your custom lambda criteria (as an example i get the type with score of 5)
ObjectPool.GetAmountInPool<yourtype>();
// Retrieves an int based on how many of this type are in the pool