Beispiel #1
0
        /// <summary>
        /// 清空对象池
        /// </summary>
        public void ClearCache()
        {
            List <uint> tempList = new List <uint>();

            foreach (uint key in mObjectPoolDic.Keys)
            {
                List <TResouceObj> st = mObjectPoolDic[key];
                for (int i = st.Count - 1; i >= 0; i--)
                {
                    TResouceObj resObj = st[i];
                    if (!System.Object.ReferenceEquals(resObj.CloneObj, null) && resObj.Clear)
                    {
                        GameObject.Destroy(resObj.CloneObj);
                        mResouceObjDic.Remove(resObj.CloneObj.GetInstanceID());
                        resObj.Reset();
                        mResouceObjPool.Recycle(resObj);
                        st.Remove(resObj);
                    }
                }
                if (st.Count <= 0)
                {
                    tempList.Add(key);
                }
            }
            for (int i = 0; i < tempList.Count; i++)
            {
                uint temp = tempList[i];
                if (mObjectPoolDic.ContainsKey(temp))
                {
                    mObjectPoolDic.Remove(temp);
                }
            }
            tempList.Clear();
        }
        /// <summary>
        /// 取消异步加载资源
        /// </summary>
        /// <returns></returns>
        public bool CancleLoad(TResouceObj res)
        {
            TAsyncLoadResParam para = null;

            if (mLoadingAssetDic.TryGetValue(res.Crc, out para) && mLoadingAssetList[(int)para.Priority].Contains(para))
            {
                for (int i = para.CallbackList.Count; i > 0; i--)
                {
                    TAsyncCallBack tempCallBack = para.CallbackList[i];
                    if (tempCallBack != null && res == tempCallBack.ResObj)
                    {
                        tempCallBack.Reset();
                        mAsyncCallBackPool.Recycle(tempCallBack);
                        para.CallbackList.Remove(tempCallBack);
                    }
                }
                if (para.CallbackList.Count <= 0)
                {
                    para.Reset();
                    mLoadingAssetList[(int)para.Priority].Remove(para);
                    mAsyncLoadResParamPool.Recycle(para);
                    mLoadingAssetDic.Remove(res.Crc);
                    return(true);
                }
            }
            return(false);
        }
    protected void UnspawnAll()
    {
        foreach (KeyValuePair <SpawnChild, List <GameObject> > item in Spawnall)
        {
            List <GameObject> golist = item.Value;
            for (int i = 0; i < golist.Count; i++)
            {
                GameObject g = golist[i];
                g.GetComponent <Image>().color = Color.white;
                switch (item.Key)
                {
                case SpawnChild.FirstPoolItem:
                    selfMainpool.Recycle(g);
                    break;

                case SpawnChild.SecendPoolItem:
                    selfSecendpool.Recycle(g);
                    break;

                default:
                    break;
                }
            }
        }
        Spawnall.Clear();
    }
Beispiel #4
0
    public void Recycle(EnemyControllerBase controllerBase, bool
                        immediatelyDelete = false, bool countEnemyKill = true)
    {
        CurrentKillCount++;
        if (!controllerBase.isDead)
        {
            controllerBase.onDied();
        }
        if (controllerBase.isBoomMonster && keepMakeMonster)
        {
            AllocateMonster();
        }
        if (countEnemyKill)
        {
            _needKillEnemyCount--;
        }
        if (_needKillEnemyCount == 0)
        {
            //Debug.Log("_needKillEnemyCount==0");
            keepMakeMonster = false;
        }

        if (!immediatelyDelete)
        {
            StartCoroutine(RecycleIEnu(controllerBase));
        }
        else
        {
            _boomEnemysPool.Recycle(controllerBase);
            if (_boomEnemys.Count > 0)
            {
                _boomEnemys.Dequeue();
            }
            controllerBase.gameObject.SetActive(false);
        }
    }
Beispiel #5
0
        public void SimpleObjectPool_Test()
        {
            var fishPool = new SimpleObjectPool <Fish>(() => new Fish(), null, 100);

            Assert.AreEqual(fishPool.CurCount, 100);
            var fishOne = fishPool.Allocate();

            Assert.AreEqual(fishPool.CurCount, 99);
            fishPool.Recycle(fishOne);
            Assert.AreEqual(fishPool.CurCount, 100);
            for (var i = 0; i < 10; i++)
            {
                fishPool.Allocate();
            }
            Assert.AreEqual(fishPool.CurCount, 90);
        }
Beispiel #6
0
    void Start()
    {
        var fishPool = new SimpleObjectPool <Fish>(() => new Fish(), null, 100);

        Debug.LogFormat("fishPool.CurCount:{0}", fishPool.CurCount);
        var fishOne = fishPool.Allocate();

        Debug.LogFormat("fishPool.CurCount:{0}", fishPool.CurCount);
        fishPool.Recycle(fishOne);
        Debug.LogFormat("fishPool.CurCount:{0}", fishPool.CurCount);
        for (var i = 0; i < 10; i++)
        {
            fishPool.Allocate();
        }
        Debug.LogFormat("fishPool.CurCount:{0}", fishPool.CurCount);
    }
Beispiel #7
0
    public void SetRangeData(bool onoff, float range = 0)
    {
        _update  = onoff;
        _accTime = 0;
        _accterm = 0;

        if (onoff)
        {
            _effect.Play();
        }
        else
        {
            _effect.Stop();
            SimpleObjectPool.Recycle(gameObject);
        }
    }
Beispiel #8
0
        void UnLoadAssetBundle(string name)
        {
            TAssetBundleItem item = null;
            uint             crc  = CRC32.GetCRC32(name);

            if (mAssetBundleItemDic.TryGetValue(crc, out item) && item != null)
            {
                item.ReCount--;
                if (item.ReCount <= 0 && item.AB != null)
                {
                    item.AB.Unload(true);
                    item.Reset();
                    mAssetBundleItemPool.Recycle(item);
                    mAssetBundleItemDic.Remove(crc);
                }
            }
        }
Beispiel #9
0
        private void Start()
        {
            var fishPool = new SimpleObjectPool <Fish>(() => new Fish(), null, 100);

            Log.I("fishPool.CurCount:{0}", fishPool.CurCount);

            var fishOne = fishPool.Allocate();

            Log.I("fishPool.CurCount:{0}", fishPool.CurCount);

            fishPool.Recycle(fishOne);

            Log.I("fishPool.CurCount:{0}", fishPool.CurCount);

            for (int i = 0; i < 10; i++)
            {
                fishPool.Allocate();
            }

            Log.I("fishPool.CurCount:{0}", fishPool.CurCount);
        }
Beispiel #10
0
        public void SimpleObjectPool_Test()
        {
            var fishPool = new SimpleObjectPool <Fish>(() => new Fish(), (hh) => { Debug.Log(hh.GetType().Name); }, 100);

            Assert.AreEqual(fishPool.CurCount, 100);

            var fishOne = fishPool.Allocate();

            Assert.AreEqual(fishPool.CurCount, 99);

            fishPool.Recycle(fishOne);

            Assert.AreEqual(fishPool.CurCount, 100);

            for (var i = 0; i < 10; i++)
            {
                fishPool.Allocate();
            }

            Assert.AreEqual(fishPool.CurCount, 90);
        }
Beispiel #11
0
    public void SimpleObjectPool_Test()
    {
        var fishPool = new SimpleObjectPool <Fish>(() => new Fish(), null, 100);

        Debug.Log(fishPool.CurCount);


        var fishOne = fishPool.Allocate();

        Debug.Log(fishPool.CurCount);

        fishPool.Recycle(fishOne);

        Debug.Log(fishPool.CurCount);

        for (var i = 0; i < 10; i++)
        {
            fishPool.Allocate();
        }

        Debug.Log(fishPool.CurCount);
    }
Beispiel #12
0
 public static void Recycle(this GameObject obj)
 {
     SimpleObjectPool.Recycle(obj);
 }
Beispiel #13
0
 public void RecycleBullet(MonsterBulletCharacter monsterBulletCharacter)
 {
     _bulletPool.Recycle(monsterBulletCharacter);
 }
        private void Start()
        {
            #region 简易对象池示例
            SimpleObjectPool <EFrameSimpleMsg> simpleMsgPool = new SimpleObjectPool <EFrameSimpleMsg>(
                () => new EFrameSimpleMsg(),
                simpleMsg => { simpleMsg.Reset(); },
                10
                );

            Debug.Log(string.Format("simpleMsgPool.CurCount: {0}", simpleMsgPool.CurCount));

            var t_simpleMsg = simpleMsgPool.Allocate();

            Debug.Log(string.Format("simpleMsgPool.CurCount: {0}", simpleMsgPool.CurCount));

            var res = simpleMsgPool.Recycle(t_simpleMsg);

            Debug.Log(string.Format("simpleMsgPool.CurCount: {0}", simpleMsgPool.CurCount));

            EFrameSimpleMsg[] msgs = new EFrameSimpleMsg[5];

            for (int i = 0; i < msgs.Length; i++)
            {
                msgs[i] = simpleMsgPool.Allocate();
            }

            Debug.Log(string.Format("simpleMsgPool.CurCount: {0}", simpleMsgPool.CurCount));

            for (int i = 0; i < msgs.Length; i++)
            {
                simpleMsgPool.Recycle(msgs[i]);
            }

            Debug.Log(string.Format("simpleMsgPool.CurCount: {0}", simpleMsgPool.CurCount));
            #endregion

            #region 安全对象池示例
            SafeObjectPool <EFrameSafeMsg> safeMsgPool = SafeObjectPool <EFrameSafeMsg> .Instance;

            safeMsgPool.Init(100, 50);

            Debug.Log(string.Format("safeMsgPool.CurCount: {0}", safeMsgPool.CurCount));

            var msg = EFrameSafeMsg.Allocate();

            Debug.Log(string.Format("safeMsgPool.CurCount: {0}", safeMsgPool.CurCount));

            msg.Recycle2Cache();

            Debug.Log(string.Format("safeMsgPool.CurCount: {0}", safeMsgPool.CurCount));

            EFrameSafeMsg[] safeMsgs = new EFrameSafeMsg[40];

            for (int i = 0; i < safeMsgs.Length; i++)
            {
                safeMsgs[i] = EFrameSafeMsg.Allocate();
            }

            Debug.Log(string.Format("safeMsgPool.CurCount: {0}", safeMsgPool.CurCount));

            for (int i = 0; i < safeMsgs.Length; i++)
            {
                safeMsgs[i].Recycle2Cache();
            }

            Debug.Log(string.Format("safeMsgPool.CurCount: {0}", safeMsgPool.CurCount));

            #endregion
        }