Esempio n. 1
0
        public static void Load(string name)
        {
            string path = PathRouter.ScenesFolder + name;

            using (var timer = LoadTimer.Start <SceneLoader>(path))
            {
                if (null == SceneResource.Current || SceneResource.Current.Path != path)
                {
                    SceneResource sceneResource = new SceneResource(path);
                    try
                    {
                        if (Application.isEditor && IsDev)
                        {
                            BuildSettingsCheck(path);
                            SceneManager.LoadScene(path);
                        }
                        else
                        {
                            string bundleName        = path + ".unity" + PathRouter.AssetBundleSuffix;
                            var    assetBundleHandle = AssetBundleLoader.Load(bundleName);
                            SceneManager.LoadScene(path);
                            sceneResource.AddDependency(assetBundleHandle);
                        }

                        if (null != SceneResource.Current)
                        {
                            SceneResource.Current.Dispose();
                            AssetSystem.Instance.GarbageCollect();
                        }

                        SceneResource.Current = sceneResource;
                        AssetSystem.Instance.AddAsset(sceneResource);
                    }
                    catch (Exception e)
                    {
                        sceneResource.Dispose();
                        throw new ApplicationException("Error when loading Scene:" + path, e);
                    }
                }
            }
        }
Esempio n. 2
0
        protected override async Task AsyncRun()
        {
            SceneResource sceneResource = new SceneResource(Url);

            try
            {
                if (Application.isEditor && IsDev)
                {
                    BuildSettingsCheck(Url);
                    await LoadSceneAsync();
                }
                else
                {
                    string bundleName        = Url + ".unity" + PathRouter.AssetBundleSuffix;
                    var    assetBundleHandle = await AssetBundleLoader.AsyncLoad(
                        bundleName, v => Progress = v * 0.5f);

                    await LoadSceneAsync(0.5f);

                    sceneResource.AddDependency(assetBundleHandle);
                }

                if (null != SceneResource.Current)
                {
                    SceneResource.Current.Dispose();
                    AssetSystem.Instance.GarbageCollect();
                }

                SceneResource.Current = sceneResource;
                AssetSystem.Instance.AddAsset(sceneResource);
                Finish(sceneResource);
            }
            catch (Exception e)
            {
                Finish(null);
                sceneResource.Dispose();
                throw new ApplicationException("Error when loading Scene:" + Url, e);
            }
        }