public JPoolObject GetObjectFromPool(string key)
    {
        JPoolObject founded = null;

        foundedQueue = null;
        if (!pool.TryGetValue(key, out foundedQueue))
        {
            foundedQueue = new Queue <JPoolObject>();
            pool.Add(key, foundedQueue);
        }

        if (foundedQueue.Count <= 0)
        {
            JPoolData data = GetPoolData(key);
            founded = Instantiate(data.prefabObject, new Vector3(0, 10000, 0), Quaternion.identity);
        }
        else
        {
            founded = foundedQueue.Dequeue();
        }

        founded.gameObject.SetActive(true);
        founded.OnOutFromPool();
        return(founded);
    }
    public virtual void PushObject <T>(JPoolObject obj)
    {
        obj.OnReturnToPool();
        Type type = typeof(T);

        pool.Add(type, obj);
    }
Example #3
0
    public void RecycleObject(GameObject go)
    {
        JPoolObject pobj = go.GetComponent <JPoolObject>();

        if (pobj)
        {
            pobj.Recycle();
        }
        else
        {
            Destroy(go);
        }
    }
    public void ReturnToPool(string key, JPoolObject poolObject)
    {
        foundedQueue = null;
        if (!pool.TryGetValue(key, out foundedQueue))
        {
            foundedQueue = new Queue <JPoolObject>();
            pool.Add(key, foundedQueue);
        }

        poolObject.gameObject.SetActive(false);
        poolObject.sleepTime = Time.realtimeSinceStartup;
        poolObject.OnReturnToPool();
        foundedQueue.Enqueue(poolObject);
    }
    public virtual JPoolObject GetObject <T>()
    {
        JPoolObject foundedObject = null;
        Type        type          = typeof(T);

        if (!pool.TryGetValueOne(type, out foundedObject))
        {
            Debug.LogError($"Not foundex {type.ToString()}");
            return(null);
        }



        foundedObject.OnOutFromPool();
        return(foundedObject);
    }