public static GameObject Instantiate(GameObject prefab, Vector3 position, Quaternion rotation) { PoolObject po = GetOrCreatePoolObject(prefab); List <GameObject> sceneObjectsList; if (objectsByPoolObject.TryGetValue(po, out sceneObjectsList)) { if (sceneObjectsList.Any(x => !x.activeInHierarchy)) { return(ActivateAvailableObject(position, rotation, sceneObjectsList)); } } else { objectsByPoolObject.Add(po, new List <GameObject>()); CreateParent(po); } return(InstantiateNewObject(prefab, position, rotation, po)); }
public void Add(PoolObject item) { poolObjects.Add(item); }
private static GameObject InstantiateNewObject(GameObject prefab, Vector3 position, Quaternion rotation, PoolObject po) { Transform parent = parentByPoolObject[po]; GameObject createdObject = Object.Instantiate(prefab, position, rotation, parent); objectsByPoolObject[po].Add(createdObject); return(createdObject); }