adr*_*992 4 c# unity-game-engine unity5
我正在创建一个针对Samsung Gear VR的Unity应用程序.我目前有两个场景:
从第一个场景开始,我想在后台加载第二个场景,并在加载后切换到它.当新场景在后台加载时,用户应该保持移动头部以查看VR环境的任何部分的能力.
我正在使用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;
}
Run Code Online (Sandbox Code Playgroud)
使用该代码,场景永远不会改变.
我试过这个典型SceneManager.LoadScene("name")的情况,在这种情况下,场景在30秒后正确变化.
这应该工作
while(async.progress < 0.9f){
progressText.text = async.progress.ToString();
yield return null;
}
Run Code Online (Sandbox Code Playgroud)
其次,isDone除非场景已激活,否则我已经看到永远不会设置为true的情况.删除这些行:
while(!async.isDone){
yield return null;
}
Run Code Online (Sandbox Code Playgroud)
最重要的是,您将在第一个while循环中锁定代码.添加一个yield,以便应用程序可以继续加载代码.
所以你的整个代码看起来像这样:
IEnumerator loadScene(){
AsyncOperation async = SceneManager.LoadAsyncScene("Scene", LoadSceneMode.Single);
async.allowSceneActivation = false;
while(async.progress <= 0.89f){
progressText.text = async.progress.ToString();
yield return null;
}
async.allowSceneActivation = true;
}
Run Code Online (Sandbox Code Playgroud)
然而,你问题的最大罪魁祸首是锁定第一个while循环.
| 归档时间: |
|
| 查看次数: |
6741 次 |
| 最近记录: |