IEnumerator SetupRoutine() { while (!readyForSetup) { yield return(null); } setupRoutine = null; try { AtSetup(); isSetup = true; } catch (Exception exc) { Dbg.LogExcRelease(this, exc); Dbg.LogRelease(this, "APP: Setup failed"); UE.Debug.Break(); setupRoutine = null; yield break; } setupRoutine = null; OnSceneLoaded(); }
void Shutdown() { if (setupRoutine != null) { StopCoroutine(setupRoutine); setupRoutine = null; } if (!isSetup) { return; } try { AtShutdown(); } catch (Exception exc) { Dbg.LogExcRelease(this, exc); Dbg.LogRelease(this, "APP: Shutdown failed"); } // Not going to be any more setup isSetup = false; }
protected void Awake() { if (instance != null) { Destroy(gameObject); return; } instance = this; // Has to be in root hierarchy for DontDestroyOnLoad if (transform.parent != null) { transform.parent = null; } DontDestroyOnLoad(gameObject); _timeScale = new Combinder <float>((float prevVal, float newVal) => Mathf.Min(prevVal, newVal), defaultVal: 1.0f); _timeScale.onChanged += OnTimeScaleChanged; StartCoroutine(PostRenderRoutine()); try { AtAwake(); } catch (Exception exc) { Dbg.LogExcRelease(this, exc); Dbg.LogErrorRelease(this, "APP: Awake failed"); UE.Debug.Break(); } }
IEnumerator OnSceneLoadedRoutine() { Dbg.LogRelease(this, "APP: Scene loaded"); while (!readyForSceneLoad) { yield return(null); } Scene activeScene = SceneManager.GetActiveScene(); if (activeScene.name == splashSceneName) { Dbg.LogRelease(this, "APP: Scene was splash"); // Null here already because after this we're done setupRoutine = null; for (int buildIndex = 0; buildIndex < SceneManager.sceneCountInBuildSettings; ++buildIndex) { string sceneName = Path.GetFileNameWithoutExtension(SceneUtility.GetScenePathByBuildIndex(buildIndex)); bool validSceneName = !string.IsNullOrEmpty(sceneName) && sceneName != loadingSceneName && sceneName != splashSceneName ; if (validSceneName) { Dbg.LogRelease(this, "APP: Found first scene \"{0}\"", sceneName); LoadScene(sceneName); yield break; } } Dbg.LogErrorRelease(this, "APP: Did not find a first scene to load"); yield break; } Dbg.LogRelease(this, "APP: Disabling Gravity"); Vector3 gravityToRestore = Physics.gravity; Physics.gravity = Vector3.zero; try { FindAndSetupState(); } catch (Exception exc) { Dbg.LogExcRelease(exc); Dbg.LogErrorRelease(this, "APP: State setup failed"); UE.Debug.Break(); } Dbg.LogRelease(this, "APP: Restoring Gravity"); Physics.gravity = gravityToRestore; setupRoutine = null; }