예제 #1
0
        public void Initialize(AdditiveSceneComponent component)
        {
            if (config != null)
            {
                return;
            }

            config = Resources.Load <SceneManagerConfig>("SceneManagerConfig");
            if (config == null)
            {
                throw new Exception($"{this} Cant load scene manager config from Resources/SceneManagerConfig");
            }

            string parentSceneName = component.Config.SceneParent.Name;

            SceneConfig scene = config.Scenes.FirstOrDefault(x => x.Name.ToLowerInvariant() == parentSceneName.ToLowerInvariant());

            if (scene == null)
            {
                throw new Exception($"{this} no configuration for the current scene: {parentSceneName}");
            }

            if (scene.Async)
            {
                SceneManagement.LoadSceneAsync(scene.Name, UnityEngine.SceneManagement.LoadSceneMode.Single);
            }
            else
            {
                SceneManagement.LoadScene(scene.Name);
            }
        }
예제 #2
0
        public IEnumerator LoadSceneAsync(CocoSceneID sceneId)
        {
            if (!LoadSceneModule(sceneId))
            {
                yield break;
            }

            yield return(SceneManager.LoadSceneAsync(m_CurrSceneModule.Data.sceneName));
        }
예제 #3
0
        private IEnumerator LoadAdditiveScene(string scene)
        {
            AsyncOperation async = SceneManagement.LoadSceneAsync(scene, UnityEngine.SceneManagement.LoadSceneMode.Additive);

            while (!async.isDone)
            {
                yield return(null);
            }

            Publisher.Publish(EventTopics.SceneLoadAdditiveLoaded, scene);
        }
예제 #4
0
        static void StateChange(PlayModeStateChange change)
        {
            string currentSceneName = EditorSceneManager.GetActiveScene().name;

            if (EditorApplication.isPlaying)
            {
                EditorApplication.playModeStateChanged -= StateChange;

                if (currentSceneName[0] != '_')
                {
                    if (currentSceneName != _menuScene)
                    {
                        // NOTE(SpectatorQL): We're in playmode, right after having pressed Play.
                        RuntimeSceneManager.LoadSceneAsync(_menuScene);
                    }
                }
            }
        }
예제 #5
0
 IEnumerator LoadChangeScene()
 {
     yield return(UnitySceneManager.LoadSceneAsync(_name));
 }
예제 #6
0
        private IEnumerator RunLoad <T>(string scenePath, object bundle, string transition = TransitionFactory.FadeTransition) where T : IScene
        {
            if (IsLoading)
            {
                Debug.LogWarning("Scenes is loading, do not load again");
                yield break;
            }

            isLoading = true;
            var lst = curScene;

            if (lst != null)
            {
                //VRProfiler.StartWatch(string.Format("[LoadingScene] Scene: {0} UnLoad ", lst.Name));
                Events.DispathMsg(Event_OnUnload, lst.Name);
                lst.Unload();
                //VRProfiler.StopWatch();
            }

            //VRProfiler.StartWatch("[LoadingScene] Transition In ");
            curScene = null;
            if (null == mask)
            {
                mask = TransitionFactory.CreateTransition(transition);
            }
            mask.DontDestroyOnLoad();
            SetRaycast(false);
            yield return(mask.TransitIn(TransitionLength));

            //VRProfiler.StopWatch();


            //VRProfiler.StartWatch("[LoadingScene] Switch To Scene: Loading ");
            //销毁场景物件
            if (lst != null)
            {
                Destroy(lst.UnityObject);
            }
            //切换至空场景
            UnitySceneMgr.LoadScene(VRScene.Loading);
            //VRProfiler.StopWatch();

            //VRProfiler.StartWatch("[LoadingScene] Unload Unused Assets ");
            //资源回收
            yield return(1);

            yield return(Resources.UnloadUnusedAssets());

            GC.Collect();
            //VRProfiler.StopWatch();

            //VRProfiler.StartWatch(string.Format("[LoadingScene] Switch to Scene:{0} ",scenePath));
            //切换下一场景
            yield return(UnitySceneMgr.LoadSceneAsync(scenePath));

            SetRaycast(true);


            //场景handler
            curScene                 = GetMissingSceneObj <T>();
            curScene.Name            = scenePath;
            curScene.gameObject.name = curScene.GetType().Name;
            //配置场景相关内容
            curScene.name = "[scene] " + curScene.Name;
            // VRProfiler.StopWatch();
            //场景加载完成
            isLoading = false;
            //VRProfiler.StartWatch(string.Format("[LoadingScene] Scene: {0} Preload ", curScene.Name));
            curScene.Preload(bundle);
            //VRProfiler.StopWatch();



            //等待场景
            //VRProfiler.StartWatch(string.Format("[LoadingScene] Scene: {0} Wait ", curScene.Name));
            yield return(curScene.Wait());

            // VRProfiler.StopWatch();

            //VRProfiler.StartWatch(string.Format("[LoadingScene] Scene: {0} Loaded ", curScene.Name));
            curScene.Loaded();
            Events.DispathMsg(Event_OnLoaded, curScene.Name);
            //VRProfiler.StopWatch();

            //VRProfiler.StartWatch("[LoadingScene] Transition Out ");
            //黑幕打开
            if (null != mask)
            {
                yield return(mask.TransitOut(TransitionLength));

                mask.DestroySelf();
                mask = null;
            }
            //VRProfiler.StopWatch();

            yield return(1);

            //加载完成
            curScene.Opened();
        }
예제 #7
0
        public SceneManager()
        {
            var        subscriber       = new Subscriber();
            var        currentSceneName = "";
            GameObject loading          = null;

            // Scene Loaded
            subscriber.Subscribe(EventTopics.SceneAwake, () => currentSceneName = SceneManagement.GetActiveScene().name);

            // Scene Change
            subscriber.Subscribe <string>(EventTopics.SceneChange, (triggerName) =>
            {
                SceneConfig scene = config.Scenes.FirstOrDefault(x => String.Equals(x.Name, currentSceneName, StringComparison.InvariantCultureIgnoreCase));
                if (scene == null)
                {
                    throw new Exception($"{this} no configuration for the current scene: {currentSceneName}");
                }

                SceneNext next = scene.LinkTo.FirstOrDefault(x => String.Equals(x.TriggerName, triggerName, StringComparison.InvariantCultureIgnoreCase));
                if (next == null)
                {
                    throw new Exception($"{this} no configuration for this trigger scene: {currentSceneName}, trigger: {triggerName}");
                }

                SceneConfig nextConfig = config.Scenes.FirstOrDefault(x => String.Equals(x.Name, next.SceneName.Name, StringComparison.InvariantCultureIgnoreCase));
                if (nextConfig == null)
                {
                    throw new Exception($"{this} no configuration for this scene: {next.SceneName.Name}");
                }

                if (nextConfig.Async)
                {
                    SceneManagement.LoadSceneAsync(next.SceneName.Name, UnityEngine.SceneManagement.LoadSceneMode.Single);
                }
                else
                {
                    SceneManagement.LoadScene(next.SceneName.Name);
                }
            });

            // Scene Loading
            subscriber.Subscribe(EventTopics.SceneLoading, () =>
            {
                loading = Object.Instantiate(config.LoadingPrefab);
                loading.GetComponent <CanvasGroup>().alpha = 1;
            });

            subscriber.Subscribe(EventTopics.SceneLoaded, () =>
            {
                loading.GetComponent <CanvasGroup>().alpha = 0;
                Object.Destroy(loading);
                loading = null;
            });

            // Additive Scene
            subscriber.Subscribe <string>(EventTopics.SceneLoadAdditive, (name) =>
            {
                SceneConfig scene = config.Scenes.FirstOrDefault(x => x.Name.ToLowerInvariant() == currentSceneName.ToLowerInvariant());
                if (scene == null)
                {
                    throw new Exception($"{this} no configuration for the current scene: {currentSceneName}");
                }

                SceneAdditiveConfig additive = scene.Additives.FirstOrDefault(x => x.Name.ToLowerInvariant() == name.ToLowerInvariant());
                if (additive == null)
                {
                    throw new Exception($"{this} no configuration for this additive scene: {currentSceneName}, additive: {name}");
                }

                currentScene.StartCoroutine(LoadAdditiveScene(additive.Name));
            });

            subscriber.Subscribe <string>(EventTopics.SceneLoadAdditiveAwake, (name) =>
            {
                // if the additive scene is opened directly
                if (currentScene == null)
                {
                    return;
                }

                SceneConfig scene = config.Scenes.FirstOrDefault(x => x.Name.ToLowerInvariant() == currentSceneName.ToLowerInvariant());
                if (scene == null)
                {
                    throw new Exception($"{this} no configuration for the current scene: {currentSceneName}");
                }

                SceneAdditiveConfig additive = scene.Additives.FirstOrDefault(x => x.Name.ToLowerInvariant() == name.ToLowerInvariant());
                if (additive == null)
                {
                    throw new Exception($"{this} no configuration for this additive scene: {currentSceneName}, additive: {name}");
                }

                if (additive.ActiveOnLoad)
                {
                    SceneManagement.SetActiveScene(SceneManagement.GetSceneByName(additive.Name));
                }
            });
        }
예제 #8
0
        public IEnumerator UnloadCurrSceneAsync()
        {
            yield return(SceneManager.LoadSceneAsync(EMPTY_SCENE_NAME));

            UnloadCurrSceneModule();
        }
예제 #9
0
 public void LoadScene(int sceneIndex)
 {
     SceneLoader.LoadSceneAsync(sceneIndex);
 }