Пример #1
0
    /// <summary>
    ///     回收目标实例至对应池
    /// </summary>
    /// <param name="clone">目标实例</param>
    /// <param name="delay">延迟时间</param>
    public 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))
            {
                // Remove the association
                Links.Remove(clone);

                pool.Despawn(clone, delay);
            }
            else
            {
                if (LeanGameObjectPool.TryFindPoolByClone(clone, ref pool))
                {
                    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
        private bool Exists()
        {
            if (LeanPool.Links.TryGetValue(gameObject, out cachedPool) == true)
            {
                return(true);
            }

            if (LeanGameObjectPool.TryFindPoolByClone(gameObject, ref cachedPool) == true)
            {
                return(true);
            }

            return(false);
        }