示例#1
0
        /// <summary>This allows you to despawn a clone via GameObject, with optional delay.</summary>
        public static void Despawn(GameObject clone, float delay = 0.0f)
        {
            if (clone != null)
            {
                var pool = default(LeanGameObjectPool);

                // Try and find the pool associated with this clone
                if (Links.TryGetValue(clone, out pool) == true)
                {
                    // Remove the association
                    Links.Remove(clone);

                    pool.Despawn(clone, delay);
                }
                else
                {
                    if (LeanGameObjectPool.TryFindPoolByClone(clone, ref pool) == true)
                    {
                        pool.Despawn(clone, delay);
                    }
                    else
                    {
                        Debug.LogWarning("You're attempting to despawn a gameObject that wasn't spawned from this pool", clone);

                        // Fall back to normal destroying
                        Object.Destroy(clone);
                    }
                }
            }
            else
            {
                Debug.LogWarning("You're attempting to despawn a null gameObject", clone);
            }
        }
示例#2
0
        /// <summary>This allows you to detach a clone via GameObject, with optional delay.
        /// A detached clone will act as a normal GameObject, requiring you to manually destroy or otherwise manage it.
        /// NOTE: If this clone has been despawned then it will still be parented to the pool.</summary>
        public static void Detach(GameObject clone)
        {
            if (clone != null)
            {
                var pool = default(LeanGameObjectPool);

                // Try and find the pool associated with this clone
                if (Links.TryGetValue(clone, out pool) == true)
                {
                    // Remove the association
                    Links.Remove(clone);

                    pool.Detach(clone);
                }
                else
                {
                    if (LeanGameObjectPool.TryFindPoolByClone(clone, ref pool) == true)
                    {
                        pool.Detach(clone);
                    }
                    else
                    {
                        Debug.LogWarning("You're attempting to detach a gameObject that wasn't spawned from this pool", clone);
                    }
                }
            }
            else
            {
                Debug.LogWarning("You're attempting to detach a null gameObject", clone);
            }
        }
示例#3
0
        /// <summary>This allows you to despawn a clone via GameObject, with optional delay.</summary>
        public static void Despawn(GameObject clone, float delay = 0.0f)
        {
            if (clone != null)
            {
                var pool = default(LeanGameObjectPool);

                // Try and find the pool associated with this clone
                if (Links.TryGetValue(clone, out pool) == true)
                {
                    // Remove the association
                    Links.Remove(clone);

                    pool.Despawn(clone, delay);
                }
                else
                {
                    if (LeanGameObjectPool.TryFindPoolByClone(clone, ref pool) == true)
                    {
                        pool.Despawn(clone, delay);
                    }
                    else
                    {
                        Debug.LogWarning("You're attempting to despawn a gameObject that wasn't spawned from a pool (or the pool was destroyed).", clone);

                        // Fall back to normal destroying
#if UNITY_EDITOR
                        if (Application.isPlaying == false)
                        {
                            Object.DestroyImmediate(clone);

                            return;
                        }
#endif
                        if (delay > 0.0f)
                        {
                            Object.Destroy(clone);
                        }
                        else
                        {
                            Object.Destroy(clone, delay);
                        }
                    }
                }
            }
            else
            {
                Debug.LogWarning("You're attempting to despawn a null gameObject.", clone);
            }
        }