Exemplo n.º 1
0
    public GameObject CreateObj(bool isAutoActive = false)
    {
        GameObject obj;

        if (m_pool.Count > 0)
        {
            obj = m_pool.Last.Value;
            m_pool.RemoveLast();


            //obj.transform.position = m_source.transform.position;
            //obj.transform.rotation = m_source.transform.rotation;
        }
        else
        {
            obj = GameObject.Instantiate(m_source) as GameObject;
            GameObjectPoolIdentifier pool = obj.GetComponent <GameObjectPoolIdentifier>();
            if (pool == null)
            {
                pool = obj.AddComponent <GameObjectPoolIdentifier>();
            }
            pool.OwnPool = this;
        }
        obj.name = m_source.name;
        if (Application.isEditor)
        {
            obj.transform.parent = m_selfRoot.transform;
        }
        obj.SetActive(isAutoActive);
        return(obj);
    }
Exemplo n.º 2
0
    public void ReleaseObj(GameObject obj)
    {
        if (obj == null)
        {
            return;
        }
        GameObjectPoolIdentifier poolIdentifier = obj.GetComponent <GameObjectPoolIdentifier>();

        if (null != poolIdentifier)
        {
            if (poolIdentifier.OwnPool == null)
            {
                Debug.LogError("OwnPool is null, obj name:" + obj.name);
            }
            else
            {
                poolIdentifier.OwnPool.ReleaseObj(obj);
            }
        }
        else
        {
            GameObject.Destroy(obj);
        }
    }