/// <summary> /// Collects the object to its pool then deactivates it, ready for next use. /// If it doesn't have a pool, it will be destroyed. /// This will call <see cref="IPoolable.OnPoolUnSpawn"/> /// </summary> static public void SendToPool(GameObject obj) { // ++ Instead of getComponent compare to an array PoolMember member = obj.GetComponent <PoolMember>(); if (member) { member.OnRecycleToPool(); member.myPool.PushToPool(obj); } else { Debug.LogWarning("Object '" + obj.name + "' wasn't spawned from a pool. Destroying it instead."); Object.Destroy(obj); } }
/// <summary> /// Collects the object to its pool then deactivates it, ready for next use. /// If it doesn't have a pool, it will be destroyed. /// This will call <see cref="IPoolable.OnPoolUnSpawn"/> /// </summary> static public void SendToPool(GameObject obj) { if (pools.ContainsKey(obj)) { pools[obj].PushToPool(obj.transform, true); } else { PoolMember member = obj.GetComponent <PoolMember>(); if (member) { member.OnRecycleToPool(); member.ParentPool.PushToPool(obj.transform, false); return; } // - Not even a member if (LOG_WARNINGS) { Debug.LogWarning("Object '" + obj.name + "' wasn't spawned from a pool. Destroying it instead."); } Object.Destroy(obj); } }