Unity with progress bar loading scenario and field darken solution

Source: Internet
Author: User

First say load scene show progress bar

Simply speaking, you need a +update.

Always use Ugui, progress bar with slider

Don't forget to quote

using UnityEngine.UI;
public Slider slider;

If you want to display a number percentage next to it, just add a text.

public Text text;

Assuming we're in old , we're going to the scene new, how do we load and show the progress?

Can be done directly in the old scene, or you can add an intermediate scene to display the loading progress specifically

Let's just add an intermediate scene, called Middle .

and the loaded progress bar Slder and Percent text text is created in this scene

Which means at least three scripts are required.

One hangs in the old scene, one hangs in the middle scene, and a script is responsible for passing the name of the scene new to the middle scene from the old scene

First, the script that passes the scene name

One word

public class PassSceneName{        public static string SceneName;}

Two actions in a script in an old scene
1. Be responsible for passing the name of the scene to Passscenename
2. Open the middle scene

public void GotoNewScene(){        PassSceneName.SceneName="new";        SceneManager.LoadScene("middle");}

In this way, after entering the middle scene, you can read the name of the scene to be loaded by passscenename.scenename

As a loading scenario, it is obvious that it is automatically loaded and can be executed asynchronously in the Start method

public Slider slider;public Text text;public float speed = 1.0f;private AsyncOperation op;private void Start(){        StartCoroutine(loadScene());}Ienumerator loadScene(){        slider.value = 0f;        op=SceneManager.LoadSceneAsync(PassSceneName.SceneName);        op.allowSceneActivation = false;     //加载完成不自动切换        yield return op;}private void Update(){        if(op != null)        {                float val = op.progress;                slider.value = op.progress;                int persent=(int)(val * 100);                text.text = persent + "%";                if(persent == 100)                {                        op.allowSceneActivation = true;      //允许加载完成后切换场景                }        }}

As above, the value of the slider is directly equal to the progress value of the asynchronous load.

slider.value = op.progress;

And the percent text is the progress x100 again rounding

Automatic switching of the scene is not allowed until the progress reaches 100%, up to 100% allowed

Actually, it's simple.

Besides, the problem of loading the scene, not bright, is also very simple

First, the scene definitely uses a real-time light setting.

So, in the lighting panel,

First, the auto generate before the check to cancel

Then click the Generate lighting button

As with baked, a folder with the same name will also be generated in the scene file sibling directory

There's a lightingdata, a reflectionprobe.

But unlike baked, this is not a baking scene, the process is very fast, so that later in the program to load its scene, it will not go into the scene dimmed

Unity with progress bar loading scenario and field darken solution

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.