Unity异步加载场景

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

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;string

}io

相关文章
相关标签/搜索