Unity3D Development (III): Scenario Management plug-in Scene Manager

Source: Internet
Author: User

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;}}



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.