Exemplo n.º 1
0
        public IEnumerator LoadedAsset(AssetBundleManager assetBundleManager, string assetBundleName, string assetName)
        {
            assetBundleName = assetBundleManager.RemapVariantName(assetBundleName);
            bundleLoaded    = assetBundleManager.LoadAssetBundleAsync(assetBundleName);
            yield return(bundleLoaded);

            AssetBundleRequest request = bundleLoaded.assetBundle.LoadAssetAsync <MultiSceneSetup>(assetName);

            yield return(request);

            MultiSceneSetup multiSceneSetup = request.asset as MultiSceneSetup;

            if (multiSceneSetup != null)
            {
                maxLoaded = multiSceneSetup.scenePaths.Length;
                for (int i = 0; i < multiSceneSetup.scenePaths.Length; i++)
                {
                    indexLoaded = i;
                    string bundleName;
                    if (!assetBundleManager.GetBundleName(multiSceneSetup.scenePaths[i], out bundleName))
                    {
                        continue;
                    }
                    yield return(LoadedAsset(assetBundleManager, bundleName, Path.GetFileNameWithoutExtension(multiSceneSetup.scenePaths[i])));
                }
            }
            indexLoaded = maxLoaded;
        }
Exemplo n.º 2
0
        internal AssetBundleLoaded LoadAssetBundleAsync(string bundleName, AssetBundleLoaded dependencyAssetBundle = null)
        {
            AssetBundleLoaded assetBundleLoad;

            if (!cacheMap.TryGetValue(bundleName, out assetBundleLoad))
            {
                Debug.Log("Load asset bundle " + bundleName);
                string[] dependencies = assetBundleManifest.GetAllDependencies(bundleName);
                assetBundleLoad = new AssetBundleLoaded(bundleName, dependencies);
                cacheMap.Add(bundleName, assetBundleLoad);

                AssetBundleCreateRequest loading = AssetBundle.LoadFromFileAsync(GetBundlePath(bundleName));
                loadingMap.Add(bundleName, loading);

                for (int i = 0; i < dependencies.Length; i++)
                {
                    dependencies[i] = RemapVariantName(dependencies[i]);
                    LoadAssetBundleAsync(dependencies[i], assetBundleLoad);
                }

                if (!dependenciesMap.ContainsKey(bundleName))
                {
                    dependenciesMap.Add(bundleName, dependencies);
                }
            }
            assetBundleLoad.AddDependencyAssetBundle(dependencyAssetBundle);
            assetBundleLoad.referencedCount++;
            return(assetBundleLoad);
        }
Exemplo n.º 3
0
        public IEnumerator LoadedAsset(AssetBundleManager assetBundleManager, string assetBundleName, string sceneName, LoadSceneMode mode)
        {
            assetBundleName = assetBundleManager.RemapVariantName(assetBundleName);
            bundleLoaded    = assetBundleManager.LoadAssetBundleAsync(assetBundleName);
            yield return(bundleLoaded);

            operation = SceneManager.LoadSceneAsync(sceneName, mode);
            operation.allowSceneActivation = !notActivatedScene;
        }
Exemplo n.º 4
0
        public virtual Object LoadBundleAsset(string bundleName, string assetName, System.Type type)
        {
            AssetBundleLoaded assetBundleWrap = LoadAssetBundle(bundleName);

            if (assetBundleWrap.assetBundle == null)
            {
                return(null);
            }
            return(assetBundleWrap.assetBundle.LoadAsset(assetName, type));
        }
Exemplo n.º 5
0
        public virtual bool LoadBundleScene(string bundleName, string sceneName, LoadSceneMode mode)
        {
            AssetBundleLoaded assetBundleWrap = LoadAssetBundle(bundleName);

            if (assetBundleWrap.assetBundle == null)
            {
                return(false);
            }
            SceneManager.LoadScene(sceneName, mode);
            return(true);
        }
Exemplo n.º 6
0
        public void AddDependencyAssetBundle(AssetBundleLoaded dependencyAssetBundle)
        {
            if (dependencyAssetBundle == null)
            {
                return;
            }

            mainAssetBundleList.Add(dependencyAssetBundle);
            if (selfLoadedCompleted)
            {
                dependencyAssetBundle.AddLoadedDependency();
            }
        }
        public IEnumerator LoadedAsset(AssetBundleManager assetBundleManager, string assetBundleName, string assetName, System.Type type)
        {
            assetBundleName = assetBundleManager.RemapVariantName(assetBundleName);
            bundleLoaded    = assetBundleManager.LoadAssetBundleAsync(assetBundleName);
            yield return(bundleLoaded);

            if (bundleLoaded.assetBundle != null)
            {
                request        = bundleLoaded.assetBundle.LoadAssetAsync(assetName, type);
                this.assetName = assetName;
            }
            isCompleted = true;
        }
Exemplo n.º 8
0
        protected void UnloadAssetBundleInternal(string bundleName, bool forceUnload)
        {
            AssetBundleLoaded bundle = null;

            if (!cacheMap.TryGetValue(bundleName, out bundle))
            {
                return;
            }

            if (!forceUnload && --bundle.referencedCount > 0)
            {
                return;
            }

            bundle.assetBundle.Unload(false);
            cacheMap.Remove(bundleName);
        }
Exemplo n.º 9
0
        public virtual Object LoadBundleSubAsset(string bundleName, string assetName, string subAssetName, System.Type type)
        {
            AssetBundleLoaded loadAssetBundle = LoadAssetBundle(bundleName);

            if (loadAssetBundle.assetBundle == null)
            {
                return(null);
            }
            Object[] subAssets = loadAssetBundle.assetBundle.LoadAssetWithSubAssets(assetName, type);
            foreach (Object subAsset in subAssets)
            {
                if (subAsset.name == subAssetName)
                {
                    return(subAsset);
                }
            }
            return(null);
        }
Exemplo n.º 10
0
        internal AssetBundleLoaded LoadAssetBundle(string bundleName, AssetBundleLoaded dependencyAssetBundle = null)
        {
            AssetBundleLoaded loadAssetBundle;

            if (!cacheMap.TryGetValue(bundleName, out loadAssetBundle))
            {
                Debug.Log("Load asset bundle " + bundleName);
                AssetBundle bundle       = AssetBundle.LoadFromFile(GetBundlePath(bundleName));
                string[]    dependencies = assetBundleManifest.GetAllDependencies(bundleName);
                loadAssetBundle = new AssetBundleLoaded(bundleName, dependencies);
                loadAssetBundle.SetLoadedAssetBundle(bundle);
                cacheMap.Add(bundleName, loadAssetBundle);

                if (bundle == null)
                {
                    Debug.LogError("Load asset bundle failed: " + bundleName);
                    loadAssetBundle.referencedCount++;
                    return(null);
                }

                for (int i = 0; i < dependencies.Length; i++)
                {
                    dependencies[i] = RemapVariantName(dependencies[i]);
                    LoadAssetBundle(dependencies[i], loadAssetBundle);
                }

                if (!dependenciesMap.ContainsKey(bundleName))
                {
                    dependenciesMap.Add(bundleName, dependencies);
                }
            }

            loadAssetBundle.AddDependencyAssetBundle(dependencyAssetBundle);
            loadAssetBundle.referencedCount++;
            return(loadAssetBundle);
        }