public void AddObjectToPool(PoolObjTypes type, int quantity) { for (int i = 0; i < quantity; i++) { GameObject obj = Instantiate(pools[pools.FindIndex(_ => _.type == type)].prefab); obj.name = type.ToString(); obj.SetActive(false); poolsDictionary[type].Enqueue(obj); } }
public GameObject SpawnObject(PoolObjTypes type, Vector3 position, Quaternion rotation) { if (poolsDictionary[type].Count == 0) { AddObjectToPool(type, 1); } GameObject newObj = poolsDictionary[type].Dequeue(); newObj.SetActive(true); newObj.transform.position = position; newObj.transform.rotation = rotation; return(newObj); }
public void ReturnToPool(PoolObjTypes type, GameObject obj) { obj.SetActive(false); poolsDictionary[type].Enqueue(obj); }