2 using System.Collections.Generic;
4 namespace HKI.Core.Pooling
13 [AddComponentMenu(
"HKI/Misc/Object Pool")]
20 [SerializeField] GameObject Prefab = null;
25 [SerializeField]
bool Prewarm =
true;
30 [SerializeField]
int InstanctiatedAmountOnPrewarm = 1;
33 Queue<GameObject> objectQueue =
new Queue<GameObject>();
34 List<GameObject> pooledObjects =
new List<GameObject>();
41 for(
int i = 0; i < InstanctiatedAmountOnPrewarm; i++)
53 if(objectQueue.Count == 0)
56 return objectQueue.Dequeue();
66 objectQueue.Enqueue(obj);
78 objectQueue.Enqueue(obj);
85 GameObject obj = Instantiate<GameObject>(Prefab);
88 pooledObjects.Add(obj);
89 objectQueue.Enqueue(obj);
GameObject GetNewPooledObject()
This function will return an unused object.
void GiveBack(GameObject obj)
This function will recieve an object that isn't used anymore and will handle it. This function will n...
void InstanctiateObject()
void GiveBackActiveObject(GameObject obj)
It's similar to the GiveBack function but this function will ensure that the GameObject is disabled...
This MonoBehaviour is a pool controls a pool of objects (GameObjects).