/// <summary> /// 清理缓存释放资源 /// </summary> /// <param name="assetBundleName"></param> public static void ClearCache(int assethashcode) { CacheData cache = null; caches.TryGetValue(assethashcode, out cache); if (cache != null) { if (lockedCaches.Contains(assethashcode)) //被锁定了不能删除 { #if UNITY_EDITOR Debug.LogWarningFormat(" the cache ab({0},{1}) are locked,cant delete. frameCount{2} ", cache.assetBundleKey, cache.assetBundle, Time.frameCount); #endif } else { #if HUGULA_LOADER_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; cache.Dispose(); if (alldep != null) { for (int i = 0; i < alldep.Length; i++) { cachetmp = GetCache(alldep[i]); if (cachetmp != null) { cachetmp.count--;// = cachetmp.count - 1; //因为被销毁了。 if (cachetmp.count <= 0) { ClearCache(cachetmp.assetHashCode); } } } } } } else { Debug.LogWarningFormat("ClearCache {0} fail ", assethashcode); } }
private static void m_ActionOnRelease(CacheData cd) { cd.Dispose(); }