public void QuitGame()
     {
         GlobalSignals.Get <GameIsQuittingSignal>().Dispatch();
 #if UNITY_EDITOR
         UnityEditor.EditorApplication.isPlaying = false;
 #endif
         Application.Quit();
     }
Beispiel #2
0
 private void OnDisable()
 {
     GlobalSignals.Get <ShakeSignal>().RemoveListener(Shake);
     if (shakeRoutine != null)
     {
         StopCoroutine(shakeRoutine);
     }
 }
 protected override void Awake()
 {
     base.Awake();
     instance = this;//low-key singleton
     GlobalSignals.Get <RequestQuitGameSignal>().AddListener(QuitGame);
     SceneManager.sceneLoaded += SceneLoadedHandler;
     DG.Tweening.DOTween.Init();
     DG.Tweening.DOTween.SetTweensCapacity(500, 20);
 }
        private IEnumerator LoadLevelRoutine(Action LoadSceneAction)
        {
            //reset flags
            IsTransitioning = true;
            levelHasLoaded  = false;

            var transitionWait = new WaitForSeconds(
                ScreenTransitionController.TransitionDuration);

            //preserve coroutine with immortality!
            myTransform.parent = null;     // dontdestroyonload only works on objects at root
            DontDestroyOnLoad(gameObject); //don't destroy while we are loading the level

            //fade out
            ScreenTransitionController.Instance
            .TriggerTransition(outTransitionMessage);    //hide scene
            transitionOUTClip.Value.PlaySFX();

            //wait for the darkness to envelope you, and then a bit longer
            yield return(transitionWait);

            //last call before a scene is destroyed.
            GlobalSignals.Get <ScenePreUnload>().Dispatch();

            //perform scene load
            SceneManager.sceneLoaded += OnLevelLoaded; //subscribe to event
            //SceneManager.LoadScene(index);
            LoadSceneAction();                         //many ways to load a scene, but use this one.

            //wait
            yield return(waitUntilFinishedLoading); //levelHasLoaded = true

            levelHasLoaded = false;                 //reset flag

            //clean up while screen still black
            SceneManager.sceneLoaded -= OnLevelLoaded; //unsubscribe to event
            GC.Collect();                              //why not? screen is totally black now.

            //wait until next frame
            yield return(null);

            //fade into new scene
            ScreenTransitionController.Instance.
            TriggerTransition(inTransitionMessage);

            transitionINClip.Value.PlaySFX();

            //wait for scene to fully open, and just a bit longer
            yield return(transitionWait);

            //finalize
            IsTransitioning = false;
            Destroy(gameObject);//left over from previous level
        }
 protected virtual void OnDisable()
 {
     //ubsubscribe from save events
     GlobalSignals.Get <SaveStateToFile>().RemoveListener(SaveState);
     GlobalSignals.Get <LoadStateFromFile>().RemoveListener(LoadState);
 }
 protected virtual void OnEnable()
 {
     //subscribe to save events
     GlobalSignals.Get <SaveStateToFile>().AddListener(SaveState);
     GlobalSignals.Get <LoadStateFromFile>().AddListener(LoadState);
 }
Beispiel #7
0
 private void OnEnable()
 {
     GlobalSignals.Get <ShakeSignal>().AddListener(Shake);
 }
 private void SceneLoadedHandler(Scene scene, LoadSceneMode mode)
 => GlobalSignals.Get <SceneLoadedSignal>().Dispatch();
 private void OnDestroy()
 {
     GlobalSignals.Get <RequestQuitGameSignal>().RemoveListener(QuitGame);
     SceneManager.sceneLoaded -= SceneLoadedHandler;
 }