When we load a scene, if the resources of the scene is relatively small, it will quickly jump into the next scene, if the scene resources more load will be very slow, then if the user has been waiting for the user experience is poor, so we use asynchronous loading.
 
Here I use Ugui do, of course, with Ngui can also, just change the components.
 
Using Unityengine;
Using System.Collections;
Using Unityengine.ui;
public class Excessivemenupanel:monobehaviour {
Public Scrollbar progress bar in loadscrollbar;//scene
Public text loadtext;//Display progress
Use this for initialization
void Start () {
This is the ID of the buildsetting, or the string, change the following int to string
Startcoroutine (Startloading_4 (2));
}
<summary>
Load the scene, only load the scene in Buildsettings settings, I do load assetbundle loading scene is not possible
</summary>
<param name= "Scene" ></param>
<returns></returns>
Private IEnumerator startloading_4 (int scene)
{
int displayprogress = 0;
int toprogress = 0;
AsyncOperation op = application.loadlevelasync (Scene);
Op.allowsceneactivation = false;
while (Op.progress < 0.9f)
{
toprogress = (int) op.progress * 100;
while (Displayprogress < toprogress)
{
++displayprogress;
Setloadingpercentage (displayprogress);
Yield return new waitforendofframe ();
}
}
toprogress = 100;
while (Displayprogress < toprogress)
{
++displayprogress;
Setloadingpercentage (displayprogress);
Yield return new waitforendofframe ();
}
Op.allowsceneactivation = true;
}
<summary>
Set up progress bars and text
</summary>
<param name= "num" ></param>
private void Setloadingpercentage (float num)
{
loadscrollbar.size = num * 0.01F;
Loadtext.text = num. ToString () + "%";
}
}