Example #1
0
        uint ReleaseOne(string abName)
        {
            AssetBundleInstance assetBundleInstance = null;

            cache.TryGetValue(abName, out assetBundleInstance);

            if (assetBundleInstance == null)
            {
                Debug.LogErrorFormat("AssetBundleManagar cache 中没有 {0}, id {1} ", abName, GetInstanceID());
                return(0);
            }
            //引用计数减 1
            if (assetBundleInstance.Release() == 0)
            {
                assetBundleInstance.Unload();
                cache.Remove(abName);
                if (debugLog)
                {
                    Debug.LogErrorFormat("释放 {0}", abName);
                }
                return(0);
            }
            if (debugLog)
            {
                Debug.LogErrorFormat("引用减 1 {0} ReferenceCount {1}", abName, assetBundleInstance.GetReferenceCount());
            }

            return(assetBundleInstance.GetReferenceCount());
        }
Example #2
0
        /// <summary>
        /// 强制移除 不检查引用
        /// </summary>
        /// <param name="name"></param>
        public void Rem(string name)
        {
            AssetBundleInstance assetBundleInstance = null;

            cache.TryGetValue(name, out assetBundleInstance);
            if (assetBundleInstance != null)
            {
                assetBundleInstance.assetBundle.Unload(true);
                cache.Remove(name);
            }
        }
Example #3
0
        uint ReleaseOne(string abName)
        {
            //1.检测正在加载中的
            if (curAssetBundleLoader != null)
            {
                if (curAssetBundleLoader.name.Equals(abName))
                {
                    curAssetBundleLoader.Release();
                    return(curAssetBundleLoader.referenceCount);
                }
            }
            //2. 检查 是否在等待队列里
            AssetBundleLoader[] waitings = waiting.ToArray();
            AssetBundleLoader   curWaitingAssetBundleLoader;

            for (int i = 0; i < waitings.Length; i++)
            {
                curWaitingAssetBundleLoader = waitings[i];
                if (curWaitingAssetBundleLoader.name.Equals(abName))
                {
                    curWaitingAssetBundleLoader.Release();
                    return(curWaitingAssetBundleLoader.referenceCount);
                }
            }
            //3.检测缓存
            AssetBundleInstance assetBundleInstance = null;

            cache.TryGetValue(abName, out assetBundleInstance);

            if (assetBundleInstance == null)
            {
                Debug.LogErrorFormat("AssetBundleManagar cache 中没有 {0} ", abName);
                return(0);
            }
            //引用计数减 1
            if (assetBundleInstance.Release() == 0)
            {
                assetBundleInstance.Unload();
                cache.Remove(abName);
                if (debugLog)
                {
                    Debug.LogErrorFormat("释放 {0}", abName);
                }
                return(0);
            }
            if (debugLog)
            {
                Debug.LogErrorFormat("引用减 1 {0} ReferenceCount {1}", abName, assetBundleInstance.GetReferenceCount());
            }

            return(assetBundleInstance.GetReferenceCount());
        }
Example #4
0
        /// <summary>
        /// 加入缓存 Caches the new one.
        /// </summary>
        /// <param name="assetBundleLoader">Asset bundle loader.</param>
        void CacheNewOne(AssetBundleLoader assetBundleLoader)
        {
            //检测缓存
            AssetBundleInstance assetBundleInstance;

            cache.TryGetValue(curAssetBundleLoader.name, out assetBundleInstance);
            if (assetBundleInstance == null)
            {
                assetBundleInstance             = new AssetBundleInstance();
                assetBundleInstance.name        = assetBundleLoader.name;
                assetBundleInstance.assetBundle = curAssetBundleLoader.assetBundle;
                assetBundleInstance.SetReferenceCount(curAssetBundleLoader.referenceount);
                //添加到缓存
                cache.Add(curAssetBundleLoader.name, assetBundleInstance);
            }
            else
            {
                Debug.LogErrorFormat("{0} 重复加载!", assetBundleInstance);
            }
        }