/// </summary> /// 加载资源 /// </summary> /// <param name="resName">资源的相对路径名称</param> /// <param name="assetType">资源类型</param> /// <param name="callback">完成回调</param> /// <returns>返回该资源唯一的加载器</returns> public static AssetFileLoader LoadAssetFile(string resName, EAssetType assetType, OnAssetFileLoad callback) { if (AssetLoadMode == EAssetLoadMode.EditorMode) { string loadPath = resName; return(GetFileLoader(assetType, loadPath, callback, null)); } else if (AssetLoadMode == EAssetLoadMode.ResourceMode) { string loadPath = resName; return(GetFileLoader(assetType, loadPath, callback, null)); } else if (AssetLoadMode == EAssetLoadMode.BundleMode) { if (BundleMethod == null) { throw new Exception("AssetSystem.BundleMethod is null."); } string manifestPath = AssetPathHelper.ConvertResourcePathToManifestPath(resName); string loadPath = BundleMethod.GetAssetBundleLoadPath(manifestPath); return(GetFileLoader(assetType, loadPath, callback, manifestPath)); } else { throw new NotImplementedException($"{AssetLoadMode}"); } }
/// <summary> /// 从缓存列表里获取加载器,如果不存在创建一个新的加载器并添加到列表 /// </summary> public static AssetFileLoader GetFileLoader(EAssetType assetType, string loadPath, OnAssetFileLoad 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(assetType, loadPath); } else if (AssetLoadMode == EAssetLoadMode.ResourceMode) { newLoader = new AssetResourceLoader(assetType, loadPath); } else if (AssetLoadMode == EAssetLoadMode.BundleMode) { newLoader = new AssetBundleLoader(assetType, loadPath, manifestPath); } else { throw new NotImplementedException($"{AssetLoadMode}"); } // 新增下载需求 _fileLoaders.Add(newLoader); newLoader.LoadCallback = callback; newLoader.Reference(); //引用计数 newLoader.Update(); //立刻轮询 return(newLoader); }