Exemple #1
0
        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();
            }
        }
Exemple #2
0
        private bool unload <TAsset>(string key, bool unloadAllObjects) where TAsset : class
        {
            key = key.ToLower();
            ContentManifest.AssetEntry assetEntry = getAssetEntry(key);
            TAsset indexedAsset = getIndexedAsset <TAsset>(key);

            if (indexedAsset != null)
            {
                string bundleKey = assetEntry.BundleKey;
                if (!string.IsNullOrEmpty(bundleKey) && bundleManager.IsMounted(assetEntry.BundleKey))
                {
                    bundleManager.UnmountBundle(bundleKey, unloadAllObjects);
                }
                assetIndex.Remove(assetEntry.Key);
                return(true);
            }
            return(false);
        }