c# - 无法通过 LoadSceneAsync 加载 EasyAr 场景
问题描述
我试图通过脚本 b 异步加载 EasyAR 场景。但它不起作用。
SceneManager.LoadSceneAsync("Scene_name")
如果我尝试使用加载场景,它会起作用
SceneManager.LoadScene("Scene_name")
问题是:有没有办法异步加载它?
使用 c#。
在安卓设备上测试。
Unity 2018.3.12f
Easy AR 版本。3.0
谢谢!
新代码更新:
private void WallSceneLoader()
{
_loaderGameObject.SetActive(true);
var asyncScene = SceneManager.LoadSceneAsync(Constants.Scenes.AR_SCENE);
asyncScene.allowSceneActivation = false;
while (asyncScene.progress < 0.9f)
{
var progress = Mathf.Clamp01(asyncScene.progress / 0.9f);
_loaderBar.value = progress;
}
Debug.Log("asyncScene.isDone = true");
asyncScene.allowSceneActivation = true;}
_loader.gameObject
它只是带有进度条的滑块。
解决方案
通过在“正常”方法中使用此while
循环,您无论如何都会阻塞线程,因此您在这里失去了异步的全部优势。
你宁愿做的是在协程中使用它,就像它实际上也在示例中显示的那样SceneManager.LoadSceneAsync
private IEnumerator WallSceneLoader()
{
_loaderGameObject.SetActive(true);
var asyncScene = SceneManager.LoadSceneAsync(Constants.Scenes.AR_SCENE);
asyncScene.allowSceneActivation = false;
while (asyncScene.progress < 0.9f)
{
var progress = Mathf.Clamp01(asyncScene.progress / 0.9f);
_loaderBar.value = progress;
// tells Unity to pause the routine here
// render the frame and continue from here in the next frame
yield return null;
}
Debug.Log("asyncScene.isDone = true");
asyncScene.allowSceneActivation = true;
}
然后StartCoroutine
在你想调用它的地方使用
StartCoroutine(WalSceneLoader());
推荐阅读
- jquery - 获得多个 ajax 调用的一个进度
- angular - 当 mat-select 表单域处于焦点时,角度 mat-label 消失
- reactjs - 使用单个类组件 spfx/react/typescript 时如何将一个表单分成几个不同的页面
- html - 我的页脚比应有的大一倍
- java - 如何更新显示更新对象属性的 JAVA FX 元素(标签、列表等)
- android - 无法在模拟器中安装应用程序 - 空间不足
- python - 检查没有正则表达式的字符串
- android - 没有音频的 Chrome MediaSession API
- python - Pandas Dataframe 中的部分字符串匹配
- terraform - 访问资源组 terraform 中的所有资源信息