public override AssetRequest <TAsset> LoadAsync <TAsset>(string deviceList, ref ContentManifest.AssetEntry entry, AssetLoadedHandler <TAsset> handler = null) { if (bundleManager.IsUnmounting(entry.BundleKey)) { bundleManager.CancelUnmount(entry.BundleKey); } AssetRequest <TAsset> assetRequest; if (bundleManager.IsMounted(entry.BundleKey)) { BundleMount bundle = bundleManager.GetBundle(entry.BundleKey); if (entry.Extension.Equals("unity")) { assetRequest = new SceneAssetBundleRequest <TAsset>(entry.Key, entry.BundleKey, null); assetRequest.Finished = true; } else { assetRequest = bundle.LoadAsync(entry.Key, entry.AssetPath, handler); } } else { AsyncAssetBundleRequest <TAsset> asyncAssetBundleRequest = ((!entry.Extension.Equals("unity")) ? new AsyncAssetBundleRequest <TAsset>(entry.Key, null) : new SceneAssetBundleRequest <TAsset>(entry.Key, entry.BundleKey, null)); assetRequest = asyncAssetBundleRequest; CoroutineRunner.StartPersistent(loadBundleAndDependenciesAsync(deviceList, entry, asyncAssetBundleRequest, handler), this, "loadBundleAndDependenciesAsync"); } return(assetRequest); }
private IEnumerator waitForBundlesToLoad <TAsset>(string key, string assetPath, List <AssetRequest <AssetBundle> > bundleRequests, bool pinBundles, AsyncAssetBundleRequest <TAsset> assetRequest, AssetLoadedHandler <TAsset> handler) where TAsset : class { yield return(new CompositeCoroutineReturn(bundleRequests.ToArray())); _ = bundleRequests[0]; BundleMount[] bundleMounts = new BundleMount[bundleRequests.Count]; bool isMountSuccessful = true; HashSet <BundleMount> successfullyMountedBundles = new HashSet <BundleMount>(); for (int i = 0; i < bundleRequests.Count; i++) { AssetRequest <AssetBundle> assetRequest2 = bundleRequests[i]; if (!bundleManager.IsMounted(assetRequest2.Key)) { if (assetRequest2.Asset != null) { successfullyMountedBundles.Add(bundleMounts[i] = bundleManager.MountBundle(assetRequest2.Key, assetRequest2.Asset, pinBundles)); } else { isMountSuccessful = false; Log.LogErrorFormatted(this, "Bundle asset for bundle {0} was null", assetRequest2.Key); } } else { bundleMounts[i] = bundleManager.GetBundle(assetRequest2.Key); } activeMountRequests.Remove(assetRequest2.Key); } if (isMountSuccessful) { BundleMount rootMount = bundleMounts[0]; if (!assetPath.EndsWith(".unity")) { assetRequest.Request = rootMount.LoadAsync <TAsset>(key, assetPath).Request; yield return(assetRequest); } else { rootMount.IsPinned = true; assetRequest.Finished = true; } } else { Log.LogErrorFormatted(this, "Mount was not successful, asset {0} will be null", key); foreach (BundleMount item in successfullyMountedBundles) { bundleManager.UnmountBundle(item.Key, unloadAllLoadedObjects: true); } } handler?.Invoke(key, assetRequest.Asset); for (int i = 0; i < bundleRequests.Count; i++) { AssetRequest <AssetBundle> assetRequest2 = bundleRequests[i]; assetRequest2.Dispose(); } }