拓冰建站拓冰建站
首页 / 资讯中心 / 正文

Unity导出WebGL工程,并部署本地web服务器

WebGL打包设置修改在Build Settings-PlayerSettings-Other Settings-Rendering将Color Space 设置为Gamma将Lightmap Encoding 设置为NormalQuality在Build Settings-PlayerSettings-Publishing Settings勾选Decompression Fallback打包完成配置修改之后可以直接在Build界面选择Build And Run构建结束后会由Unity自动部署可以正常打开网页。如果选择的是Build导出WebGL工程。直接在本地点击index.html会出现以下报错。需要部署web服务器才可以正常访问。下文会部署本地nginx服务器解决该问题部署Nginx安装NginxWindows端到niginx的官网http://nginx.org/en/download.html下载稳定版本之后将下载的zip解压后直接双击nginx.exe运行Mac端在命令行输入下方指令安装ngnixbrew install ngnix安装完成后可以看到以下的输出日志其中 /opt/homebrew/etc/nginx/nginx.conf 就是nginx配置所在的位置修改配置打开conf/niginx.conf将端口号和server_name改为一个未被占用的端口号和本机的ip地址server { #这里填一个未被占用的端口 listen 8080; #这里填本机ip server_name 10.244.115.20; #charset koi8-r; #access_log logs/host.access.log main; location / { #这里填unity导出的webgl工程地址 root D:\UnityProjects\DiceGameWeb; index index.html index.htm; } }重新加载配置修改完配置之后需要重新加载nginx配置在nginx.exe所在的目录下运行./nginx -s reload运行webgl工程最后将配置中填写的本机地址和端口号拼接在一起访问http://10.244.115.20:8080/index.html可以正常运行问题处理Unable to parse Build/DiceGameWeb.framework.js.br! If using custom web server, verify that web server is sending .br files with HTTP Response Header Content-Encoding: br. Brotli compression may not be supported over HTTP connections. Migrate your server to use HTTPS.BuildSetting-PlayerSettings-Player-Settings for WebGL-Publishing Settings-Compression Format把Compression Format改成Disabled或者Gzip执行nginx指令报错nginx: [error] open() /opt/homebrew/var/run/nginx.pid failed (2: No such file or directory)原因是nginx的pid丢失所以执行 nginx -c /opt/homebrew/etc/nginx/nginx.conf 的指令 后面xx/nginx.conf 是nginx.config实际存储的地址
分享:

看完干货,该让你的企业上线了

免费需求沟通 · 48 小时内出具建站方案 · 河南本地可上门