Exemple #1
0
        /// <summary>
        /// 立即卸载资源
        /// </summary>
        /// <returns></returns>
        public static bool Unload(int hashcode)
        {
            CacheData cache = TryGetCache(hashcode);

            if (cache != null && cache.count == 0)
            {
                caches.Remove(cache.assetHashCode);  //删除
                CacheData.Release(cache);
                return(true);
            }
            else if (cache != null)
            {
#if UNITY_EDITOR
                Debug.LogWarningFormat("<color=#ff00ff> can't unload  cache assetBundle={0},keyhashcode({1},count={2})   </color>", cache.assetBundleKey, cache.assetHashCode, cache.count);
#endif
            }
            return(false);
        }
Exemple #2
0
        /// <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})   </color>", cache.assetBundleName, cache.count);
#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(abName, out cachedChild) && cachedChild.count >= 1)
                        {
                            if (--cachedChild.count == 0)
                            {
                                ABDelayUnloadManager.AddDep(tmpName);
                            }
                            // 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);
        }