在游戏中,经常可以看到从一个关卡跳到另一个关卡时,有一个显眼的进度条,研究了下,其时也很简单:
public void LoadAScene()
{
StartCoroutine(LoadSceneAsync("SampleScene"));
}
IEnumerator LoadSceneAsync(string sceneName)
{
AsyncOperation operation = SceneManager.LoadSceneAsync(sceneName);
operation.allowSceneActivation = false;
while (!operation.isDone)
{
#if UNITY_EDITOR
Debug.Log("Progress is :" + operation.progress);
#endif
float progress = Mathf.Clamp01(operation.progress / 0.9f);
ProgressSlider.value = progress;
ProgressText.text = ((int)progress * 100).ToString() + "%";
yield return null;
}
operation.allowSceneActivation = true;
}