public static PooledObject Get(GameObject prefab) { ObjectPool objPool = GetPool(prefab.name, typeof(GameObject)); if (objPool == null) { objPool = CreateNewPool(prefab); } PooledObject newObject = objPool.GetObject(prefab); newObject.Activate(); return(newObject); }
public PooledObject GetObject(GameObject prefab) { PooledObject retrievedObject = null; var disabledObjects = m_PoolGameObjects.Where(x => x.gameObject.activeSelf == false); if (disabledObjects.Any()) { retrievedObject = disabledObjects.First(); } else { retrievedObject = CreateNewObject(prefab); } retrievedObject.Activate(); return(retrievedObject); }
public PooledObject GetInstance(Transform parent) { PooledObject obj = null; if (pooledObjects.Count > 0) { obj = pooledObjects[0]; pooledObjects.RemoveAt(0); } else { Transform newParent = parent == null? transform : parent; obj = Instantiate(prefab, newParent); obj.pool = this; } obj.Activate(); return(obj); }