问题描述
如题的问题是在windows项目发布webgl时遇到的,unity3d的版本是2020.3.12f1c1,部署平台是iis,运行浏览器是chrome。如果是其它的版本的unity,该方法可能不适用。
具体表现是打开webgl网页后加载至8-90%时卡住,而且不会再提升加载进度:
f12打开console窗口报错:
uncaught syntaxerror: invalid or unexpected token (at build.framework.js.gz:1:1)
uncaught referenceerror: unityframework is not defined at r.onload (build.loader.js:1:3167)
完整报错截图:
刚开始怀疑的是工程中使用的插件或者dll等模块有影响,于是我进行了一个空项目上的测试,还是一样的情况,无法正常启动至运行界面。
解决方法
禁用压缩格式(compression format:disabled):
设置完成后,再次打包放到服务器运行,还是有很多报错:
404 (not found);
build.loader.js:1 wasm streaming compile failed: typeerror: failed to execute ‘compile’ on ‘webassembly’: http status code is not ok.
both async and sync fetching of the wasm failed
完整报错:
主要是有两个文件找不到的问题(404),可以先进行修复,尝试在mine类型中添加两个文件类型。
打开iis的mime类型进行添加,左侧选中 > 点击“mime类型”:
空白处右键“添加”:
添加“.data”–“application/data”:
添加“.wasm”–“application/wasm”:
如果有其它mime类型自行添加即可。
其它web服务器可以自行搜索进行配置即可。
如上的配置修改后,启动时console窗口也不会有相关的报错,程序顺利加载进入运行场景:
参考解决方法:https://forum.unity.com/threads/uncaught-referenceerror-unityframework-is-not-defined-at-htmlscriptelement-script-onload.970611/
发表评论