Ejemplo n.º 1
0
        public GameObject pop(GameObject parent)
        {
            GameObject obj = m_pool.pop();

            if (null == obj)
            {
                if (m_pool.isEmptyUnUsed())
                {
                    reallocate();
                }
                obj = m_pool.pop();
                if (null == obj)
                {
                    return(null);
                }
            }

            //Vector3 localScale = obj.transform.localScale;

            /**
             *   set active 전에 restore 해줘야 된다. 안그러면 적용이 안됨, 왜 그런건가??
             */
            restoreDefaultColor(obj);
            obj.SetActive(true);
            if (null != parent)
            {
                if (m_isUi)
                {
                    obj.transform.SetParent(parent.transform);
                }
                else
                {
                    obj.transform.parent = parent.transform;
                }
            }
            obj.transform.position      = Vector3.zero;
            obj.transform.localScale    = m_defaultLocalScale;
            obj.transform.localRotation = Quaternion.identity;

            ObjectBasePool basePool = obj.GetComponent <ObjectBasePool>();

            if (null == basePool)
            {
                Console.error(string.Format("GameObjectBasePool component is null, {0} is not GameObjectBasePool inheritance", m_assetName));
                return(obj);
            }

            basePool.initPool();

            //Debug.LogFormat("pop {0}, instance id {1}", obj.name, obj.GetInstanceID());

            m_instanceIds.Remove(obj.GetInstanceID());

            return(obj);
        }
Ejemplo n.º 2
0
        public GameObject pop(GameObject parent, string assetBundleName, string assetName, bool isUi, bool isDontDestroy = false)
        {
            if (m_usePool)
            {
                POOL pool;
                if (!m_pools.TryGetValue(assetName, out pool))
                {
                    pool = createPool(assetBundleName, assetName, isUi, isDontDestroy);
                }

                if (null == pool)
                {
                    return(null);
                }

                return(pool.pop(parent));
            }
            else
            {
                GameObject obj = null;
                instantiatePool(new PoolInstantiateData(assetBundleName, assetName, parent, isUi), (inst, error) =>
                {
                    if (string.IsNullOrEmpty(error))
                    {
                        obj = inst;
                    }
                    else
                    {
                        OLib.Console.error(error);
                    }
                });

                if (null == obj)
                {
                    return(null);
                }

                obj.name = name;
                ObjectBasePool basePool = obj.GetComponent <ObjectBasePool>();
                if (null == basePool)
                {
                    Console.error(string.Format("ObjectBasePool component is null, {0} is not ObjectBasePool inheritance", obj.name));
                    return(null);
                }

                basePool.initPool();

                return(obj);
            }
        }