public void Push(GameObject obj) { ReservedInstances.Enqueue(obj); if (EventPush != null) { EventPush(this, obj); } }
private void Generate() { var instance = Instantiate(Prototype, transform); instance.SetActive(false); ReservedInstances.Enqueue(instance); CurrentSize++; if (EventGenerate != null) { EventGenerate(this, instance); } }
public GameObject Pop() { if (ReservedInstances.Count == 0) { Generate(); } var instance = ReservedInstances.Dequeue(); ActiveInstances.Add(instance); if (EventPop != null) { EventPop(this, instance); } return(instance); }
public void Clear() { var listActive = new Queue <GameObject>(ActiveInstances.ToList()); while (listActive.Count > 0) { GameObject.DestroyImmediate(listActive.Dequeue()); } var listReserv = new Queue <GameObject>(ReservedInstances.ToList()); while (listReserv.Count > 0) { GameObject.DestroyImmediate(listReserv.Dequeue()); } ReservedInstances = null; ActiveInstances = null; }