/// <summary> /// 清理缓存释放资源 /// </summary> /// <param name="assetBundleName"></param> public static void ClearDelay(int assethashcode) { CacheData cache = TryGetCache(assethashcode); if (cache != null) { #if HUGULA_CACHE_DEBUG HugulaDebug.FilterLogWarningFormat(cache.assetBundleKey, " <color=#8cacbc>ClearDelay Cache (assetBundle={0}) frameCount{1}</color>", cache.assetBundleKey, Time.frameCount); #endif ABDelayUnloadManager.Add(assethashcode); } else { #if UNITY_EDITOR || HUGULA_CACHE_DEBUG Debug.LogWarningFormat("ClearCache {0} fail ", assethashcode); #endif } }
/// <summary> /// 延时清理缓存释放资源 /// </summary> /// <param name="assetBundleName"></param> public static void ClearDelay(string key) { CacheData cache = TryGetCache(key); if (cache != null) { // #if HUGULA_CACHE_DEBUG // Debug.LogFormat(" <color=#8cacbc>ClearDelay Cache (assetBundle={0}),frameCount{1}</color>", cache.key, Time.frameCount); // #endif ABDelayUnloadManager.Add(key); } #if UNITY_EDITOR || !HUGULA_RELEASE else if (!ManifestManager.SimulateAssetBundleInEditor) { Debug.LogWarningFormat("ClearDelay Cache {0} is null ", key); } #endif }
/// <summary> /// 延时清理缓存释放资源 /// </summary> /// <param name="assetBundleName"></param> public static void Subtract(string key) { CacheData cached = TryGetCache(key); if (cached != null && cached.count >= 1) { #if HUGULA_CACHE_DEBUG Debug.LogFormat(" <color=#8cacbc>Subtract (assetBundle={0},count={1}) frameCount{2}</color>", cached.assetBundleName, cached.count, UnityEngine.Time.frameCount); #endif if (--cached.count == 0) //所有引用被清理。 { ABDelayUnloadManager.Add(key); //放入回收队列 }// end if (cached.count-- == 0) } #if UNITY_EDITOR else if (!ManifestManager.SimulateAssetBundleInEditor) { Debug.LogWarningFormat("Subtract cacheData {0} is null ", key); } #endif }
/// <summary> /// 安全卸载资源 /// </summary> /// <returns></returns> public static bool UnloadSecurity(string abName) { CacheData cache = TryGetCache(abName); if (cache != null && cache.count == 0) { #if HUGULA_CACHE_DEBUG Debug.LogWarningFormat("<color=#ffff00> unload cache assetBundle={0},count={1}) frameCount={2}. </color>", cache.assetBundleName, cache.count, Time.frameCount); #endif //处理依赖项目 string[] deps = null; if (m_Dependencies.TryGetValue(cache.assetBundleName, out deps)) { string tmpName; CacheData cachedChild = null; for (int i = 0; i < deps.Length; i++) { tmpName = deps[i]; if (m_Caches.TryGetValue(tmpName, out cachedChild) && cachedChild.count >= 1) { if (--cachedChild.count == 0) { ABDelayUnloadManager.Add(tmpName); } } } }//end if m_Caches.Remove(cache.assetBundleName); //删除 m_Dependencies.Remove(cache.assetBundleName);//依赖关系移除? CacheData.Release(cache); return(true); } #if UNITY_EDITOR else if (cache != null) { Debug.LogFormat("<color=#cccccc> can't unload cache assetBundle={0},count={1}) </color>", cache.assetBundleName, cache.count); } #endif return(false); }