예제 #1
0
 /// <summary>
 /// 资源回收
 /// 卸载引用计数为零的资源
 /// </summary>
 public static void Release()
 {
     for (int i = _fileLoaders.Count - 1; i >= 0; i--)
     {
         AssetFileLoader loader = _fileLoaders[i];
         if (loader.IsDone() && loader.RefCount <= 0)
         {
             loader.UnLoad(true);
             _fileLoaders.RemoveAt(i);
         }
     }
 }
예제 #2
0
        /// <summary>
        /// 从缓存列表里获取加载器,如果不存在创建一个新的加载器并添加到列表
        /// </summary>
        public static AssetFileLoader GetFileLoader(bool isStreamScene, string loadPath, System.Action <AssetFileLoader> callback, string manifestPath)
        {
            // 如果已经提交相同请求
            AssetFileLoader loader = TryGetFileLoaderInternal(loadPath);

            if (loader != null)
            {
                loader.Reference();                 //引用计数
                if (loader.IsDone())
                {
                    if (callback != null)
                    {
                        callback.Invoke(loader);
                    }
                }
                else
                {
                    if (callback != null)
                    {
                        loader.LoadCallback += callback;
                    }
                }
                return(loader);
            }

            // 创建加载器
            AssetFileLoader newLoader = null;

            if (AssetLoadMode == EAssetLoadMode.EditorMode)
            {
                newLoader = new AssetDatabaseLoader(isStreamScene, loadPath);
            }
            else if (AssetLoadMode == EAssetLoadMode.ResourceMode)
            {
                newLoader = new AssetResourceLoader(isStreamScene, loadPath);
            }
            else if (AssetLoadMode == EAssetLoadMode.BundleMode)
            {
                newLoader = new AssetBundleLoader(isStreamScene, loadPath, manifestPath);
            }
            else
            {
                throw new NotImplementedException($"{AssetLoadMode}");
            }

            // 新增下载需求
            _fileLoaders.Add(newLoader);
            newLoader.LoadCallback = callback;
            newLoader.Reference();          //引用计数
            newLoader.Update();             //立刻轮询
            return(newLoader);
        }