1. Use a stack to store the loading sequence of players in game scenarios (facilitating Back implementation and recording the ID of the current scenario)
2. Provides switching scenarios, stack pressure scenarios, and stack output scenarios.
3. Provides asynchronous Loading scenarios and Loading progress (used to display Loading entries)
DoTransition (), the Code is as follows:
Protected virtual IEnumerator DoTransition () {// Part 1: exit the animation state = SMTransitionState in the previous scenario. out; Prepare (); float time = 0; while (Process (time) {time + = Time. deltaTime; // wait for the next frameyield return 0;} // wait another frame... yield return 0; // Part 2: Ensure that the SMTransition object is not destroyed (complete subsequent animation) state = SMTransitionState. hold; DontDestroyOnLoad (gameObject); // wait another frame... yield return 0; IEnumerator loadLevel = DoLoadLevel (); while (loadLevel. moveNext () {yield return loadLevel. current;} // wait another frame... yield return 0; // Part 3: loading an animation state = SMTransitionState in a new scenario. in; Prepare (); time = 0; while (Process (time) {time + = Time. deltaTime; // wait for the next frameyield return 0;} // wait another frame... yield return 0; Destroy (gameObject );}In the subclass of SMTransition, implement the Prepare () virtual method and the Process (float elapsedTime) abstract method respectively.
protected override bool Process(float elapsedTime) {float effectTime = elapsedTime;// invert direction if necessaryif (state == SMTransitionState.In) {effectTime = duration - effectTime;}progress = SMTransitionUtils.SmoothProgress(0, duration, effectTime);return elapsedTime < duration;}
public void OnGUI() {GUI.depth = 0;Color c = GUI.color;GUI.color = new Color(1, 1, 1, progress);GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), overlayTexture);GUI.color = c;}Other SMTransition subclasses also use Process (float elapsedTime) to switch the animation effect!
PS: In asynchronous loading scenarios, Scene Manager does not provide an interface for obtaining the current loading progress. You need to implement this by yourself. In the SMTransition class
protected virtual YieldInstruction LoadLevel() {if (loadAsync) { AsyncOperation ao = Application.LoadLevelAsync(screenId); Debug.Log("Progress: " + ao.progress); return ao; //return Application.LoadLevelAsync(screenId);} else {Application.LoadLevel(screenId);return null;}}