我正在创建一个针对三星Gear VR的Unity应用程序。我目前有两个场景:
我正在使用SceneManager.LoadSceneAsync,但它无法正常工作:
- 初始场景
- 第二个场景,其中包含大量数据(加载场景需要太长时间)。
我正在使用SceneManager.LoadSceneAsync,但它无法正常工作:
// ...
StartCoroutiune(loadScene());
// ...
IEnumerator loadScene(){
AsyncOperation async = SceneManager.LoadAsyncScene("Scene", LoadSceneMode.Single);
async.allowSceneActivation = false;
while(async.progress < 0.9f){
progressText.text = async.progress+"";
}
while(!async.isDone){
yield return null;
}
async.allowSceneActivation = true;
}
使用该代码后,场景不会发生变化。
我尝试了典型的 SceneManager.LoadScene("name")
,在这种情况下,30秒后场景能够正确地更改。
async.isDone
。应该删除async.isDone
。您关于yield return null
语句的说法是正确的,但与浮点数比较无关。 - Programmerasync.progress
将始终返回确切的值0.9
。 它在完成加载时不会返回任何其他值。 即使这样做if(async.progress == 0.9f){async.allowSceneActivation = true;}
也是可以的和安全的。 您可以在这里阅读更多信息。 至于您的0.89
,这可能会导致问题,因为您将激活尚未完全加载的场景。 您的其余答案很好。 - ProgrammerallowSceneActivation
被设置为false
时才适用。在这种情况下,OP 最初将其设置为false
。 - Programmer