-
-
public void LoadGame()
-
{
-
StartCoroutine(StartLoading("001"));
-
}
-
-
private IEnumerator StartLoading(string sceneName)
-
{
-
int displayProgress = 0;
-
int toProgress = 0;
-
AsyncOperation op = Application.LoadLevelAsync(sceneName);
-
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 = false;
-
}
-
-
private void SetLoadingPercentage(int DisplayProgress)
-
{
-
proLoadingBar.value = DisplayProgress * 0.01f;
-
labProgress.text = DisplayProgress.ToString() + "%";
-
}
-
}
效果如下:(.gif图可能会有点卡,但是实际效果是完全很顺畅不会卡的。)