Exemplo n.º 1
0
        IEnumerator SetActivePhase(GM_Phase newPhase)
        {
            Debug.Log("set active phase 1 : " + newPhase.GetType().ToString());


            UN_CameraFade.ClearAll();
            bool readyToSwitch1 = false;

            UN_CameraFade.FadeToBlack(() => { readyToSwitch1 = true; }, 2.0f);      //### PJS TO DO : remove time

            IEnumerator it;

            _previousPhase = _curPhase;
            if (_previousPhase != null)
            {
                it = _previousPhase.Exit(newPhase);
                while (it.MoveNext())
                {
                    yield return(null);
                }

                UN.SetActive(_previousPhase, false);
            }

            // wait for fade to black to be done
            while (readyToSwitch1 == false)
            {
                yield return(null);
            }

            _curPhase = newPhase;
            UN.SetActive(newPhase, true);
            it = newPhase.Enter(_previousPhase);
            while (it.MoveNext())
            {
                yield return(null);
            }

            string newSceneName = newPhase.SceneName;

            if (!string.IsNullOrEmpty(newSceneName) && newSceneName != SceneManager.GetActiveScene().name)
            {
                AsyncOperation loadingOp = SceneManager.LoadSceneAsync(newSceneName);
                if (loadingOp != null)
                {
                    while (loadingOp.isDone == false)
                    {
                        yield return(null);
                    }

                    Events.SendGlobal(new SceneChangedEvent()
                    {
                        Name = _curPhase.SceneName
                    });
                }
            }

            Events.SendGlobal(new GM_GamePhaseChangedEvent()
            {
                NewPhase = _curPhase == null ? null : _curPhase.GetType(),
                OldPhase = _previousPhase == null ? null : _previousPhase.GetType()
            });

            {
                bool readyToSwitch2 = false;
                UN_CameraFade.FadeToTransparent(() => { readyToSwitch2 = true; }, 2.0f);    //### pjs todo fix time
                while (readyToSwitch2 == false)
                {
                    yield return(null);
                }
            }
            _changingState = false;

            Debug.Log("set active phase 2 : " + newPhase.GetType().ToString());
        }
Exemplo n.º 2
0
 public System.Type GetCurrentPhase()
 {
     return(_curPhase == null ? null : _curPhase.GetType());
 }