public void Release(FrostyPoolableObject pool, GameObject obj) { // No pool? Destroy object if (pool == null || pool.poolInstance == null) { GameObject.Destroy(obj); return; } // Unknown pool? Get out if (!pools.ContainsKey(pool.poolInstance)) { bool found = false; // Check if a similar pool exists and reconnect for (int i = 0; i < pools.Keys.Count; i++) { if (pools.Keys.ElementAt(i).objectType.GetInstanceID() == obj.GetInstanceID()) { pool.Connect(pools.Keys.ElementAt(i), true); found = true; break; } } if (!found) { // If not, get out return; } } Release(pool.poolInstance, obj); }
public GameObject Retrieve(FrostyPoolableObject pool, Vector3 position, Quaternion rotation) { GameObject obj = null; if (pool == null || pool.poolInstance == null) { throw new System.Exception("Invalid pool Object"); } // No pool? if (!pools.ContainsKey(pool.poolInstance)) { bool found = false; // Check if a similar pool exists and reconnect for (int i = 0; i < pools.Keys.Count; i++) { var elem = pools.Keys.ElementAt(i); if (elem.objectType.GetInstanceID() == pool.poolInstance.objectType.GetInstanceID()) { pool.Connect(pools.Keys.ElementAt(i), true); found = true; break; } } if (!found) { // If not, use Unity's built-in instantiate obj = Instantiate(pool.poolInstance.objectType); obj.transform.position = position; obj.transform.rotation = rotation; return(obj); } } return(Retrieve(pool.poolInstance, position, rotation)); }
public GameObject Retrieve(FrostyPoolableObject pool, Vector3 position) { return(Retrieve(pool, position, Quaternion.identity)); }
public GameObject Retrieve(FrostyPoolableObject pool) { return(Retrieve(pool, Vector3.zero, Quaternion.identity)); }