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); }
public override TAsset LoadImmediate <TAsset>(string deviceList, ref ContentManifest.AssetEntry entry) { if (bundleManager.IsMounted(entry.BundleKey)) { return(bundleManager.GetBundle(entry.BundleKey).LoadImmediate <TAsset>(entry.Key, entry.AssetPath)); } List <string> list = new List <string>(); list.Add(entry.BundleKey); List <string> list2 = list; list2.AddRange(bundleManager.GetDependencyKeys(entry.BundleKey)); BundleMount[] array = new BundleMount[list2.Count]; for (int i = 0; i < list2.Count; i++) { string text = list2[i]; ContentManifest.AssetEntry entry2 = createBundleEntry(text, deviceList, bundleManager.GetBundleEntry(text)); if (!bundleManager.IsMounted(text)) { AssetBundle bundle = DeviceManager.LoadImmediate <AssetBundle>(deviceList, ref entry2); BundleMount bundleMount = (array[i] = bundleManager.MountBundle(text, bundle, deviceList.Contains("sa-bundle"))); } else { array[i] = bundleManager.GetBundle(text); } } BundleMount bundleMount2 = array[0]; return(bundleMount2.LoadImmediate <TAsset>(entry.Key, entry.AssetPath)); }
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(); } }
public bool TryGetBundle(string bundleKey, out BundleMount mount) { mount = null; if (!string.IsNullOrEmpty(bundleKey) && mountedBundles.TryGetValue(bundleKey, out mount) && mount != null) { return(true); } return(false); }
public BundleMount MountBundle(string bundleKey, AssetBundle bundle, bool pinned = false) { if (IsMounted(bundleKey)) { throw new InvalidOperationException("A bundle with key '" + bundleKey + "' is already mounted."); } HashSet <BundleMount> hashSet = null; ContentManifest.BundleEntry bundleEntry; bool flag = manifest.TryGetBundleEntry(bundleKey, out bundleEntry); if (!flag) { } if (flag && manifest.TryGetDependentEntries(bundleEntry, out var dependents)) { hashSet = new HashSet <BundleMount>(); for (int i = 0; i < dependents.Length; i++) { ContentManifest.BundleEntry bundleEntry2 = dependents[i]; if (IsMounted(bundleEntry2.Key)) { hashSet.Add(GetBundle(bundleEntry2.Key)); } } } BundleMount bundleMount = new BundleMount(bundle, bundleKey, hashSet); if (hashSet == null && flag) { for (int i = 0; i < bundleEntry.DependencyBundles.Length; i++) { string bundleKey2 = bundleEntry.DependencyBundles[i]; if (TryGetBundle(bundleKey2, out var mount)) { mount.DependentMounts.Add(bundleMount); } } } mountedBundles[bundleKey] = bundleMount; bundleMount.IsPinned = pinned; bundleMount.EUnmounted += delegate { UnmountBundle(bundleKey, unloadAllLoadedObjects: false); }; return(bundleMount); }
public void UnmountUnusedBundles() { foreach (KeyValuePair <string, BundleMount> mountedBundle in mountedBundles) { BundleMount value = mountedBundle.Value; if (!IsUnmounting(mountedBundle.Key) && !value.IsPinned && value.ActiveRequestCount == 0) { int num = Time.frameCount - value.LastLoadFrame; if (num >= UnmountFrameCount) { bundlesToUnmount.Add(value); } } } for (int i = 0; i < bundlesToUnmount.Count; i++) { UnmountBundle(bundlesToUnmount[i].Key, unloadAllLoadedObjects: false); } bundlesToUnmount.Clear(); }
public void UnmountAllBundles() { List <string> list = new List <string>(); foreach (KeyValuePair <string, BundleMount> mountedBundle in mountedBundles) { BundleMount value = mountedBundle.Value; if (!IsUnmounting(mountedBundle.Key) && value.IsMounted) { if (value.IsPinned) { } list.Add(value.Key); } } for (int i = 0; i < list.Count; i++) { UnmountBundle(list[i], unloadAllLoadedObjects: false); } }
private void unloadMount(BundleMount mount, bool unloadAllLoadedObjects) { if (!IsUnmounting(mount.Key)) { return; } if (mount.IsMounted) { mount.Unload(unloadAllLoadedObjects); } if (!mount.IsDependency && manifest.TryGetBundleEntry(mount.Key, out var bundleEntry)) { for (int i = 0; i < bundleEntry.DependencyBundles.Length; i++) { string bundleKey = bundleEntry.DependencyBundles[i]; if (TryGetBundle(bundleKey, out var mount2)) { mount2.DependentMounts.Remove(mount); } } } mountedBundles.Remove(mount.Key); unmountingBundles.Remove(mount.Key); }