public void DestroyPool(PoolItemType objectType, GameObject gO) { gO.SetActive(false); _objectPool[objectType].Enqueue(gO); gO.transform.position = Vector3.zero; gO.transform.rotation = Quaternion.identity; }
public void SpawnFromPool(PoolItemType objectType, Vector3 spawnPos, Quaternion rotation) { GameObject gO = _objectPool[objectType].Dequeue(); gO.transform.position = spawnPos; gO.transform.rotation = rotation; gO.SetActive(true); }
public GameObject Retrieve(PoolItemType itemType) { var pooledObjects = _pools[itemType]; for (var i = 0; i < pooledObjects.Count; i++) { if (!pooledObjects[i].activeInHierarchy) { return(pooledObjects[i]); } } return(CreateNewObject(itemType)); }
private GameObject CreateNewObject(PoolItemType itemType) { GameObject objToCreate = null; for (var i = 0; i < _objectsToPool.Count; i++) { if (_objectsToPool[i].ItemType == itemType) { objToCreate = _objectsToPool[i].Prefab; break; } } var newObj = Instantiate(objToCreate, transform); newObj.SetActive(false); _pools[itemType].Add(newObj); return(newObj); }