-
Notifications
You must be signed in to change notification settings - Fork 3
Documentation
How to setup UnityObjectPooler in your Unity project?
Step 2). This step is completely optional but it might be useful to create a base class for your enemy,
like I did with PoolBehaviour script which implements MonoBehaviour and IEnemy interface. Look at this script for reference.
public class DroidEnemy : MonoBehaviour, IEnemy
{
}
OR
public class DroidEnemy : PoolBehaviour
{
}
Step 3). If you went with the interface solely you must implement all required methods from the interface.
For references look at the PoolBehaviour script. It is a base class that implements IEnemy and MonoBehaviour. It has all requirements implemented from the interface.
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(enemy); // Takes IEnemy type so any class that inherits IEnemy class can be passed ObjectPool.Get(EnemyType.YourCustomType); // EnemyType will be your custom enemy types ObjectPool.Get(EnemyType.YourCustomType); // This will cast your IEnemy to the concrete type passed
For some examples on using the ObjectPool class look at the ObjectPoolTests.cs There I have a scenario for all calls.