Пример #1
0
        /// <summary>
        /// 清理缓存释放资源
        /// </summary>
        /// <param name="assetBundleName"></param>
        public static void ClearCache(int assethashcode)
        {
            CacheData cache = TryGetCache(assethashcode);

            if (cache != null)
            {
                if (IsLock(assethashcode)) //被锁定了不能删除
                {
#if UNITY_EDITOR || HUGULA_CACHE_DEBUG
                    Debug.LogWarningFormat(" the cache ab({0},{1}) are locked,cant delete. frameCount{2} ", cache.assetBundleKey, cache.assetBundle, Time.frameCount);
#endif
                }
                else
                {
#if HUGULA_CACHE_DEBUG
                    Debug.LogFormat(" <color=#8cacbc>ClearCache (assetBundle={0}) frameCount{1}</color>", cache.assetBundleKey, Time.frameCount);
#endif
                    caches.Remove(assethashcode);//删除
                    int[]     alldep   = cache.allDependencies;
                    CacheData cachetmp = null;
                    CacheDataPool.Release(cache);

                    if (alldep != null)
                    {
                        for (int i = 0; i < alldep.Length; i++)
                        {
                            cachetmp = TryGetCache(alldep[i]);
                            if (cachetmp != null)
                            {
                                cachetmp.count--;// = cachetmp.count - 1; //因为被销毁了。
                                if (cachetmp.count <= 0)
                                {
                                    ClearCache(cachetmp.assetHashCode);
                                }
                            }
                        }
                    }
                }
            }
            else
            {
            #if UNITY_EDITOR || HUGULA_CACHE_DEBUG
                Debug.LogWarningFormat("ClearCache {0} fail ", assethashcode);
            #endif
            }
        }
Пример #2
0
 internal static bool AddSourceCacheDataFromWWW(AssetBundle ab, CRequest req)
 {
     if (ab)
     {
         req.isAssetBundle = true;
         CacheData cacheData = CacheDataPool.Get();
         cacheData.SetCacheData(ab, null, req.key);//缓存
         CacheManager.AddCache(cacheData);
         cacheData.allDependencies = req.allDependencies;
         cacheData.assetBundle     = ab;
         return(req.isAssetBundle);
     }
     else
     {
         req.isAssetBundle = false;
         return(false);
     }
 }