Пример #1
0
 private void OnResourceDone(Resource res)
 {
     if (res.isSucc)
     {
         List <ResourceHandlerStruct> succList;
         _succCallbacks.TryGetValue(res, out succList);
         _succCallbacks.Remove(res);
         if (succList != null)
         {
             while (succList.Count > 0)
             {
                 var callbackStruct = succList[0];
                 succList.RemoveAt(0);
                 callbackStruct.callback.Invoke(res, callbackStruct.path);
             }
         }
         res.Release();
     }
     else
     {
         //失败的话,将资源先移除掉
         if (res.refCount > 1)
         {
             CLog.LogError("DestroyResource[resPath=" + res.realPath + "],RefCount>1.");
         }
         else
         {
             _mapRes.Remove(res.realPath);
         }
         List <ResourceHandlerStruct> failList;
         _failCallbacks.TryGetValue(res, out failList);
         _failCallbacks.Remove(res);
         if (failList != null)
         {
             while (failList.Count > 0)
             {
                 var callbackStruct = failList[0];
                 failList.RemoveAt(0);
                 callbackStruct.callback.Invoke(res, callbackStruct.path);
             }
         }
         res.Release();
         if (res.refCount <= 0)
         {
             res.DestroyResource();
         }
     }
 }
Пример #2
0
        public void ReleaseUnUseRes()
        {
            //释放资源使用垃圾回收的机制(标记清除法)
            foreach (var item in _mapRes)
            {
                if (!m_setSign.Contains(item.Key) && item.Value.refCount > 0)
                {
                    m_setSign.Add(item.Key);
                    //收集依赖资源的标记
                    var lstDepend = item.Value.dependRes;
                    if (lstDepend != null)
                    {
                        for (int i = 0; i < lstDepend.Count; i++)
                        {
                            if (!m_setSign.Contains(lstDepend[i].realPath))
                            {
                                m_setSign.Add(lstDepend[i].realPath);
                            }
                        }
                    }
                }
            }
            foreach (var item in _mapRes)
            {
                if (!m_setSign.Contains(item.Key))
                {
                    m_lstRemoveKeyList.Add(item.Key);
                }
            }

            for (int i = 0; i < m_lstRemoveKeyList.Count; i++)
            {
                Resource res = _mapRes[m_lstRemoveKeyList[i]];
                RemoveAllListener(res);
                _mapRes.Remove(m_lstRemoveKeyList[i]);
                res.DestroyResource();
            }
            m_setSign.Clear();
            m_lstRemoveKeyList.Clear();
            Resources.UnloadUnusedAssets();
            GC.Collect();
        }
Пример #3
0
        public void ReleaseUnUseRes()
        {
            List <string> keyList = new List <string>();

            foreach (var item in _mapRes)
            {
                if (item.Value.refCount <= 0)
                {
                    keyList.Add(item.Key);
                }
            }
            for (int i = 0; i < keyList.Count; i++)
            {
                Resource res = _mapRes[keyList[i]];
                RemoveAllListener(res);
                _mapRes.Remove(keyList[i]);
                res.DestroyResource();
            }
            Resources.UnloadUnusedAssets();
            GC.Collect();
        }