Exemplo n.º 1
0
        /// <summary>
        /// objectManager 提供一个清除缓存的接口
        /// </summary>
        public void ClearCatch()
        {
            List <uint> tempList = new List <uint>();

            foreach (var key in m_resourcesItemPoolDic.Keys)
            {
                List <MResourceObjectItem> mResourceObjectLsit = m_resourcesItemPoolDic[key];
                for (int i = mResourceObjectLsit.Count - 1; i >= 0; i--)
                {
                    MResourceObjectItem mResourceObjectItem = mResourceObjectLsit[i];
                    m_resourceObjectDic.Remove(mResourceObjectItem.m_cloneObeject.GetInstanceID());
                    mResourceObjectItem.Reset();
                    m_resourceObjectClssPool.Recycle(mResourceObjectItem);
                }

                if (mResourceObjectLsit.Count <= 0)
                {
                    tempList.Add(key);
                }
            }

            for (int i = 0; i < tempList.Count; i++)
            {
                uint tempKey = tempList[i];
                if (m_resourcesItemPoolDic.ContainsKey(tempKey))
                {
                    m_resourcesItemPoolDic.Remove(tempKey);
                }
            }

            tempList.Clear();
        }
Exemplo n.º 2
0
        /// <summary>
        /// 清除某个对象在对象池中的所有对象
        /// </summary>
        /// <param name="resCrc">资源路径Crc</param>
        public void ClearPoolObject(uint resCrc)
        {
            List <MResourceObjectItem> mResourceObjectLsit = null;

            if (!m_resourcesItemPoolDic.TryGetValue(resCrc, out mResourceObjectLsit) || mResourceObjectLsit == null)
            {
                return;
            }
            for (int i = mResourceObjectLsit.Count - 1; i >= 0; i--)
            {
                MResourceObjectItem mResourceObjectItem = mResourceObjectLsit[i];
                if (mResourceObjectItem.m_isClear)
                {
                    mResourceObjectLsit.Remove(mResourceObjectItem);
                    mResourceObjectItem.Reset();
                    m_resourceObjectDic.Remove(mResourceObjectItem.m_cloneObeject.GetInstanceID());
                    m_resourceObjectClssPool.Recycle(mResourceObjectItem);
                    GameObject.Destroy(mResourceObjectItem.m_cloneObeject);
                }
            }

            if (mResourceObjectLsit.Count <= 0)
            {
                if (m_resourcesItemPoolDic.ContainsKey(resCrc))
                {
                    m_resourcesItemPoolDic.Remove(resCrc);
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 取消异步加载
        /// </summary>
        /// <param name="asyncGuid">异步加载GUID</param>
        public void CancleAsyncResObjectLoad(long asyncGuid)
        {
            MResourceObjectItem mResourceObjectItem = null;

            if (m_asyncResourcesObjectsDic.TryGetValue(asyncGuid, out mResourceObjectItem))
            {
                m_asyncResourcesObjectsDic.Remove(asyncGuid);
                mResourceObjectItem.Reset();
                m_resourceObjectClssPool.Recycle(mResourceObjectItem);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// ObjectManager的释放 对创建出来的Gameobject的释放
        /// </summary>
        /// <param name="gameObject">释放对象</param>
        /// <param name="maxCatchCount">最大缓存个数</param>
        /// <param name="destoryCompletly">是否彻底删除</param>
        /// <param name="isToRecycleParent">是非设置默认父节点</param>
        public void ReleaseObject(GameObject gameObject, int maxCatchCount = -1, bool destoryCompletly = false, bool isToRecycleParent = true)
        {
            if (gameObject == null)
            {
                return;
            }

            int tempInstanceId = gameObject.GetInstanceID();
            MResourceObjectItem mResourceObjectItem = null;

            if (!m_resourceObjectDic.TryGetValue(tempInstanceId, out mResourceObjectItem))
            {
                MDebug.singleton.AddErrorLog("这个对象不是用ObjectManager创建的GameObject Name:" + gameObject.name);
                return;
            }
            if (mResourceObjectItem == null)
            {
                MDebug.singleton.AddErrorLog("本地没有缓存这个GameObject Name:" + gameObject.name);
                return;
            }
            if (mResourceObjectItem.m_isAlreadyRelease)
            {
                MDebug.singleton.AddErrorLog("重复释放对象 Name:" + gameObject.name);
                return;
            }

#if UNITY_EDITOR
            gameObject.name += "(Recycle)";
#endif
            List <MResourceObjectItem> listObjectItems = null;
            //maxCatchCount == 0 说明不缓存 对象释放
            if (maxCatchCount == 0)
            {
                m_resourceObjectDic.Remove(tempInstanceId);
                MResourceManager.singleton.ReleaseResource(mResourceObjectItem, destoryCompletly);
                mResourceObjectItem.Reset();
                m_resourceObjectClssPool.Recycle(mResourceObjectItem);
            }
            else
            {
                if (!m_resourcesItemPoolDic.TryGetValue(mResourceObjectItem.m_crc, out listObjectItems) || listObjectItems == null)
                {
                    listObjectItems = new List <MResourceObjectItem>();
                    m_resourcesItemPoolDic.Add(mResourceObjectItem.m_crc, listObjectItems);
                }

                if (mResourceObjectItem.m_cloneObeject != null)
                {
                    if (isToRecycleParent)
                    {
                        mResourceObjectItem.m_cloneObeject.transform.SetParent(RecycleObjectPoolTrans);
                    }
                    else
                    {
                        mResourceObjectItem.m_cloneObeject.SetActiveEx(false);
                    }
                }

                //没有达到最大缓存个数的时候 进行缓存
                if (maxCatchCount < 0 || listObjectItems.Count < maxCatchCount)
                {
                    listObjectItems.Add(mResourceObjectItem);
                    mResourceObjectItem.m_isAlreadyRelease = true;
                    MResourceManager.singleton.DeCreaseResourceRef(mResourceObjectItem.m_crc);
                }
                else
                {
                    //多出来的资源卸载掉
                    m_resourceObjectDic.Remove(tempInstanceId);
                    MResourceManager.singleton.ReleaseResource(mResourceObjectItem, destoryCompletly);
                    mResourceObjectItem.Reset();
                    m_resourceObjectClssPool.Recycle(mResourceObjectItem);
                }
            }
            //todo
        }