void UnloadPackageByCount(string _dir, string _packageName, bool _isDispose, int _count = 1) { if (PackageManager.RemPackage(_packageName, _count, _isDispose)) { string moduleName = UAssetBundleManifestManager.ParseModuleName(_packageName); string fullModuleName = GetAssetBundlePath(_dir, moduleName, moduleName); List <string> dependence = ManifestManager.GetDependence(fullModuleName, _packageName); foreach (var v in dependence) { Unload(_dir, v, _isDispose); } } }
bool LoadAssetBundleInternal(string _dir, string _packageName, List <UAssetBundleCreateRequest> _requests, Func <string, AssetBundleCreateRequest> _getCreateRequest) { //> 检查并加载这个模块的关系依赖文件 string moduleName = UAssetBundleManifestManager.ParseModuleName(_packageName); string fullModuleName = GetAssetBundlePath(_dir, moduleName, moduleName); string fullPackgeName = GetAssetBundlePath(_dir, moduleName, _packageName); if (false == ManifestManager.Contains(fullModuleName)) { //> 加载依赖关系文件 string content = LoadPathText(fullModuleName); ManifestManager.AddManifest(fullModuleName, content); } //> 如果他已经在完成列表中,那么将他的引用++ if (PackageManager.ApplyPackage(fullPackgeName) != null) { //> 已经加载完成了 return(true); } UAssetBundleCreateRequest outRequest; if (PackageManager.TryGetRequest(fullModuleName, out outRequest)) { //> 已经处于加载状态了 _requests.Add(outRequest); return(true); } string path = fullPackgeName + "." + Manager.PackageExtension; AssetBundleCreateRequest createRequest = _getCreateRequest(path); if (createRequest == null || createRequest.isDone && createRequest.assetBundle == null) { //> 执行加载操作失败了 PackageManager.RemPackage(fullPackgeName, 1, true); return(true); } else { var request = new UAssetBundleCreateRequestUnity(createRequest, fullPackgeName, (NAME, VALUE) => { PackageManager.CompleteRequest(fullPackgeName, VALUE); }); //> 成功执行了加载 PackageManager.AddRequest(fullPackgeName, request); _requests.Add(request); return(false); } }
void LoadDependencies(string _dir, string _packageName, List <UAssetBundleCreateRequest> _requests, Func <string, AssetBundleCreateRequest> _getCreateRequest) { //> 获取某个模块下某个包的关系依赖文件 string moduleName = UAssetBundleManifestManager.ParseModuleName(_packageName); string fullModuleName = GetAssetBundlePath(_dir, moduleName, moduleName); List <string> dependValue = ManifestManager.GetDependence(fullModuleName, _packageName); if (dependValue.Count == 0) { return; } //> 记录和加载所有依赖文件 for (int i = 0; i < dependValue.Count; i++) { LoadAssetBundleInternal(_dir, dependValue[i], _requests, _getCreateRequest); } }
AssetBundle LoadAssetBundle(string _dir, string _packageName, Func <string, string> _manifestLoader, Func <string, AssetBundle> _packageLoader) { string moduleName = UAssetBundleManifestManager.ParseModuleName(_packageName); string fullPackageName = GetAssetBundlePath(_dir, moduleName, _packageName); // 以前的代码 AssetBundle target = PackageManager.ApplyPackage(fullPackageName); if (target != null) { return(target); } string fullModuleName = GetAssetBundlePath(_dir, moduleName, moduleName); if (false == ManifestManager.Contains(fullModuleName)) { //> 加载依赖关系文件 string content = _manifestLoader(fullModuleName); ManifestManager.AddManifest(fullModuleName, content); } AssetBundle package = _packageLoader(fullPackageName); if (package != null) { PackageManager.AddPackage(fullPackageName, package); //> 只有在当前AB加载成功的时候,才去载入依赖文件 List <string> dependence = ManifestManager.GetDependence(fullModuleName, _packageName); foreach (var v in dependence) { LoadAssetBundle(_dir, v, _manifestLoader, _packageLoader); } } return(package); }
public UAssetBundleSyncLoader(UAssetBundleManager _manager, UAssetBundlePool _packageManager, UAssetBundleManifestManager _manifestManager) { Manager = _manager; PackageManager = _packageManager; ManifestManager = _manifestManager; }
public UAssetBundleAsyncLoader(UAssetBundleManager _manager, UAssetBundlePool _packageManager, UAssetBundleManifestManager _manifestManager) : base(_manager, _packageManager, _manifestManager) { }