private static GameObject SpawnInternal(string name) { GameObjectPool pool = null; if (m_instance.m_goPools.TryGetValue(name, out pool)) { var go = pool.Create(); if (go != null) { goPoolsByObject.Add(go, pool); } return(go); } return(null); }
/// <summary> /// <para>The object will be despawned automatically after the specified lifetime and after particle death (if true). </para> /// </summary> public static GameObject Spawn(string name, Vector3 position, Quaternion rotation, float lifetimeInSeconds, bool waitForParticleDeath = true) { GameObjectPool pool = null; if (goPools.TryGetValue(name, out pool)) { var go = pool.Create(); go.transform.position = position; go.transform.rotation = rotation; pool.Free(go, lifetimeInSeconds, waitForParticleDeath); return(go); } Debug.Assert(pool != null, "There is no pool for " + name + ". Make sure to create one first."); return(null); }
/// <summary> /// <para>Make sure to call DeSpawn if the object isn't needed anymore. </para> /// </summary> public static GameObject Spawn(string name, Vector3 position, Quaternion rotation) { GameObjectPool pool = null; if (goPools.TryGetValue(name, out pool)) { var go = pool.Create(); go.transform.position = position; go.transform.rotation = rotation; goPoolsByObject.Add(go, pool); return(go); } Debug.Assert(pool != null, "There is no pool for " + name + ". Make sure to create one first."); return(null); }
/// <summary> /// <para>Make sure to call DeSpawn if the object isn't needed anymore. </para> /// </summary> public static GameObject Spawn(GameObject prefab) { Debug.Assert(prefab, "The requested prefab is null."); GameObject go = SpawnInternal(prefab.name); if (go == null) { // Create a pool for the prefab Debug.Log("Consider preloading the pool of objects for " + prefab.name + "."); var pool = new GameObjectPool(prefab, m_instance.m_defaultPreloadSize); if (m_instance.m_poolsGameObject) { pool.gameObject.transform.parent = m_instance.m_poolsGameObject.transform; } goPools.Add(prefab.name, pool); go = pool.Create(); goPoolsByObject.Add(go, pool); } return(go); }
public GameObject Create(GameObject parent = null) { init(); return(pool.Create(parent)); }