Unity异步加载场景

在游戏中,经常可以看到从一个关卡跳到另一个关卡时,有一个显眼的进度条,研究了下,其时也很简单:

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;

}

posted @ 2019-07-09 20:59  阿土仔  阅读(691)  评论(0编辑  收藏  举报