private IEnumerator downloadBundle(ContentManifest.BundleEntry bundleEntry)
        {
            ContentManifest.AssetEntry entry = new ContentManifest.AssetEntry(bundleEntry.Key, "www-bundle", "unity3d");
            numCurrentDownloads++;
            AssetRequest <AssetBundle> assetRequest = Content.DeviceManager.LoadAsync <AssetBundle>("www-bundle", ref entry);

            yield return(assetRequest);

            assetRequest.Asset.Unload(unloadAllLoadedObjects: true);
            numCurrentDownloads--;
        }
Exemplo n.º 2
0
        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 IEnumerator LoadBundlesForContent(AssetContentKey[] includingAssets)
        {
            Dictionary <string, ContentManifest.BundleEntry> bundlesToLoad = new Dictionary <string, ContentManifest.BundleEntry>();

            foreach (AssetContentKey assetContentKey in includingAssets)
            {
                if (manifest.AssetEntryMap.ContainsKey(assetContentKey.Key))
                {
                    string bundleKey = manifest.AssetEntryMap[assetContentKey.Key].BundleKey;
                    if (!string.IsNullOrEmpty(bundleKey) && !bundlesToLoad.ContainsKey(bundleKey) && manifest.BundleEntryMap.ContainsKey(bundleKey))
                    {
                        ContentManifest.BundleEntry value = manifest.BundleEntryMap[bundleKey];
                        bundlesToLoad.Add(bundleKey, value);
                    }
                }
            }
            caching    = true;
            background = false;
            yield return(cacheBundles(new List <ContentManifest.BundleEntry>(bundlesToLoad.Values), ignorePriority: true));
        }
 private IEnumerator cacheBundles(IList <ContentManifest.BundleEntry> sortedBundles, bool ignorePriority)
 {
     for (int i = 0; i < sortedBundles.Count; i++)
     {
         completeRatio = (float)(i - numCurrentDownloads) / (float)sortedBundles.Count;
         uint maxConcurrentDownloads = (background ? config.MaxConcurrentBackgroundDownloads : config.MaxConcurrentForegroundDownloads);
         while (numCurrentDownloads >= maxConcurrentDownloads)
         {
             maxConcurrentDownloads = (background ? config.MaxConcurrentBackgroundDownloads : config.MaxConcurrentForegroundDownloads);
             yield return(null);
         }
         if (!caching)
         {
             break;
         }
         ContentManifest.BundleEntry bundle = sortedBundles[i];
         if (ignorePriority || bundle.Priority > 0)
         {
             CoroutineRunner.StartPersistent(downloadBundle(bundle), this, "BundlePrecacheManager.downloadBundle()");
             continue;
         }
         break;
     }
     if (sortedBundles.Count > 0)
     {
         while (numCurrentDownloads > 0)
         {
             completeRatio = (float)(sortedBundles.Count - numCurrentDownloads) / (float)sortedBundles.Count;
             yield return(null);
         }
         completeRatio = (float)(sortedBundles.Count - numCurrentDownloads) / (float)sortedBundles.Count;
     }
     if (caching && completeCallback != null)
     {
         completeCallback();
     }
     yield return(null);
 }
        public IEnumerator LoadBundlesForContentPaths(ContentPath[] contentPaths)
        {
            Dictionary <string, ContentManifest.BundleEntry> bundlesToLoad = new Dictionary <string, ContentManifest.BundleEntry>();

            foreach (ContentPath contentPath in contentPaths)
            {
                string[] array = contentPath.Path.Split(new string[1] {
                    "/Resources/"
                }, StringSplitOptions.None);
                string text = "";
                if (array.Length == 2)
                {
                    text = array[1];
                }
                foreach (KeyValuePair <string, ContentManifest.AssetEntry> item in manifest.AssetEntryMap)
                {
                    bool flag = false;
                    if (string.IsNullOrEmpty(text) || item.Value.Key.IndexOf("/") == -1 || item.Value.Key.StartsWith(text.ToLower() + "/"))
                    {
                        flag = true;
                    }
                    if (flag)
                    {
                        string bundleKey = item.Value.BundleKey;
                        if (!string.IsNullOrEmpty(bundleKey) && !bundlesToLoad.ContainsKey(bundleKey) && manifest.BundleEntryMap.ContainsKey(bundleKey))
                        {
                            ContentManifest.BundleEntry value = manifest.BundleEntryMap[bundleKey];
                            bundlesToLoad.Add(bundleKey, value);
                        }
                    }
                }
            }
            caching    = true;
            background = false;
            yield return(cacheBundles(new List <ContentManifest.BundleEntry>(bundlesToLoad.Values), ignorePriority: true));
        }
        public static ContentManifest Merge(ContentManifest first, ContentManifest second)
        {
            Dictionary <string, ContentManifest.AssetEntry> dictionary = new Dictionary <string, ContentManifest.AssetEntry>(first.AssetEntryMap);

            foreach (KeyValuePair <string, ContentManifest.AssetEntry> item in second.AssetEntryMap)
            {
                dictionary[item.Key] = item.Value;
            }
            Dictionary <string, ContentManifest.BundleEntry> dictionary2 = new Dictionary <string, ContentManifest.BundleEntry>(first.BundleEntryMap);

            foreach (KeyValuePair <string, ContentManifest.BundleEntry> item2 in second.BundleEntryMap)
            {
                dictionary2[item2.Key] = item2.Value;
            }
            ContentManifest contentManifest = new ContentManifest();

            if (second != null)
            {
                contentManifest.BaseUri             = second.BaseUri;
                contentManifest.ContentVersion      = second.ContentVersion;
                contentManifest.ContentManifestHash = second.ContentManifestHash;
            }
            else if (first != null)
            {
                contentManifest.BaseUri             = first.BaseUri;
                contentManifest.ContentVersion      = first.ContentVersion;
                contentManifest.ContentManifestHash = first.ContentManifestHash;
            }
            HashSet <string> hashSet = new HashSet <string>();

            foreach (KeyValuePair <string, ContentManifest.AssetEntry> item3 in dictionary)
            {
                ContentManifest.AssetEntry value = item3.Value;
                if (!string.IsNullOrEmpty(value.BundleKey))
                {
                    hashSet.Add(value.BundleKey);
                }
            }
            foreach (KeyValuePair <string, ContentManifest.BundleEntry> item4 in dictionary2)
            {
                ContentManifest.BundleEntry value2 = item4.Value;
                if (!hashSet.Contains(value2.Key))
                {
                    continue;
                }
                string[] dependencyBundles = value2.DependencyBundles;
                foreach (string text in dependencyBundles)
                {
                    if (!string.IsNullOrEmpty(text))
                    {
                        hashSet.Add(text);
                    }
                }
            }
            Dictionary <string, ContentManifest.BundleEntry> dictionary3 = new Dictionary <string, ContentManifest.BundleEntry>();

            foreach (string item5 in hashSet)
            {
                if (string.IsNullOrEmpty(item5))
                {
                    throw new Exception("Bundle key cannot be empty when assigning it to Bundle map");
                }
                if (dictionary2.ContainsKey(item5))
                {
                    ContentManifest.BundleEntry value3 = dictionary2[item5];
                    dictionary3.Add(item5, value3);
                }
            }
            contentManifest.AssetEntryMap  = dictionary;
            contentManifest.BundleEntryMap = dictionary3;
            return(contentManifest);
        }
 private static int compareBundlesByPriority(ContentManifest.BundleEntry bundle1, ContentManifest.BundleEntry bundle2)
 {
     return(bundle2.Priority.CompareTo(bundle1.Priority));
 }
Exemplo n.º 8
0
 private static ContentManifest.AssetEntry createBundleEntry(string bundleKey, string deviceList, ContentManifest.BundleEntry bundleEntry)
 {
     return(new ContentManifest.AssetEntry(bundleKey, deviceList, "unity3d", null, null, isLocalized: false, null, isCacheOnly: false, null, bundleEntry));
 }