// 异步请求Assetbundle资源,AB是否缓存取决于是否设置为常驻包,Assets一律缓存,处理依赖 public BaseAssetBundleAsyncLoader LoadAssetBundleAsync(string assetbundleName) { #if UNITY_EDITOR if (AssetBundleConfig.IsEditorMode) { return new EditorAssetBundleAsyncLoader(assetbundleName); } #endif var loader = AssetBundleAsyncLoader.Get(); prosessingAssetBundleAsyncLoader.Add(loader); if (manifest != null) { string[] dependancies = manifest.GetAllDependencies(assetbundleName); for (int i = 0; i < dependancies.Length; i++) { var dependance = dependancies[i]; if (!string.IsNullOrEmpty(dependance) && dependance != assetbundleName) { CreateAssetBundleAsync(dependance); // A依赖于B,A对B持有引用 IncreaseReferenceCount(dependance); } } loader.Init(assetbundleName, dependancies); } else { loader.Init(assetbundleName, null); } CreateAssetBundleAsync(assetbundleName); // 加载器持有的引用:同一个ab能同时存在多个加载器,等待ab创建器完成 IncreaseReferenceCount(assetbundleName); return loader; }
// 异步请求Assetbundle资源,AB是否缓存取决于是否设置为常驻包,Assets一律缓存,处理依赖 public BaseAssetBundleAsyncLoader LoadAssetBundleAsync(string assetbundleName) { #if UNITY_EDITOR if (AssetBundleConfig.IsEditorMode) { return(new EditorAssetBundleAsyncLoader(assetbundleName)); } #endif /// 这是想是保证加载顺序的, 在 AssetPrefab 里要注意了 var loader = AssetBundleAsyncLoader.Get(); prosessingAssetBundleAsyncLoader.Add(loader); if (manifest != null) { string[] dependancies = manifest.GetAllDependencies(assetbundleName); loader.Init(assetbundleName, dependancies); //for (int i = 0; i < dependancies.Length; i++) //{ // var dependance = dependancies[i]; // if (!string.IsNullOrEmpty(dependance) && dependance != assetbundleName) // { // CreateAssetBundleAsync(dependance); // } //} //loader.Init(assetbundleName, dependancies); } else { loader.Init(assetbundleName, null); } //CreateAssetBundleAsync(assetbundleName); return(loader); }
// 异步请求Assetbundle资源,AB是否缓存取决于是否设置为常驻包,Assets一律缓存,处理依赖 public BaseAssetBundleAsyncLoader LoadAssetBundleAsync(string assetbundleName, string path = null) { #if UNITY_EDITOR if (AssetBundleConfig.IsEditorMode) { KVDebugHelper.Instance.AddAssetInfo(path, assetbundleName); if (path != null && File.Exists(path)) { return(new EditorAssetBundleAsyncLoader(assetbundleName)); } } #endif bool isIndependent = false; var loader = AssetBundleAsyncLoader.Get(); prosessingAssetBundleAsyncLoader.Add(loader); // Debug.Log($"{assetbundleName} hash {manifest.GetAssetBundleHash(assetbundleName)} isValid:{manifest.GetAssetBundleHash(assetbundleName).isValid}"); // Debug.Log($"{assetbundleName} hash {idpManifest.GetAssetBundleHash(assetbundleName)} isValid:{idpManifest.GetAssetBundleHash(assetbundleName).isValid}"); if (manifest != null && manifest.GetAssetBundleHash(assetbundleName).isValid) { string[] dependancies = manifest.GetAllDependencies(assetbundleName); for (int i = 0; i < dependancies.Length; i++) { var dependance = dependancies[i]; if (!string.IsNullOrEmpty(dependance) && dependance != assetbundleName) { CreateAssetBundleAsync(dependance); // A依赖于B,A对B持有引用 IncreaseReferenceCount(dependance); } } loader.Init(assetbundleName, dependancies); } else if (idpManifest != null && idpManifest.GetAssetBundleHash(assetbundleName).isValid) { isIndependent = true; string[] dependancies = idpManifest.GetAllDependencies(assetbundleName); for (int i = 0; i < dependancies.Length; i++) { var dependance = dependancies[i]; if (!string.IsNullOrEmpty(dependance) && dependance != assetbundleName) { CreateAssetBundleAsync(dependance); // A依赖于B,A对B持有引用 IncreaseReferenceCount(dependance); } } loader.Init(assetbundleName, dependancies); } else { loader.Init(assetbundleName, null); } CreateAssetBundleAsync(assetbundleName, isIndependent); // 加载器持有的引用:同一个ab能同时存在多个加载器,等待ab创建器完成 IncreaseReferenceCount(assetbundleName); return(loader); }