Unity WebGL发布及Ubuntu Apache服务器部署

  • Unity 中WebGL的设置
  • Ubuntu Apache web服务器搭建
  • 网页修改
  • 附一:Ubuntu 文件操作常用命令
  • 附二:Apache 服务器常用操作命令

Unity 中WebGL的设置

  1. 使用压缩格式:Project Settings->Player->Publishing Settings,将Compression Format设置为Gzip,Decompression Fallback设置为true
  2. 发布:Build Settings->Build,我是发布到新建的html文件夹

Ubuntu Apache web服务器搭建

  1. 安装 apache(Ubuntu20.04)
sudo apt-get install apache2
  1. 设置web资源,将之前发布的html文件夹拷贝到/var/www/html

  2. 添加配置文件,html/Build新建以下.htaccess文件【Unity文档】

# This configuration file should be uploaded to the server as "<Application Folder>/Build/.htaccess"
# NOTE: "mod_mime" Apache module must be enabled for this configuration to work.
<IfModule mod_mime.c># The following lines are required for builds without decompression fallback, compressed with gzip
RemoveType .gz
AddEncoding gzip .gz
AddType application/octet-stream .data.gz
AddType application/wasm .wasm.gz
AddType application/javascript .js.gz
AddType application/octet-stream .symbols.json.gz# The following lines are required for builds without decompression fallback, compressed with Brotli
RemoveType .br
RemoveLanguage .br
AddEncoding br .br
AddType application/octet-stream .data.br
AddType application/wasm .wasm.br
AddType application/javascript .js.br
AddType application/octet-stream .symbols.json.br# The following line improves loading performance for uncompressed builds
AddType application/wasm .wasm# Uncomment the following line to improve loading performance for gzip-compressed builds with decompression fallback
# AddEncoding gzip .unityweb# Uncomment the following line to improve loading performance for brotli-compressed builds with decompression fallback
# AddEncoding br .unityweb</IfModule>
  1. 重启服务器
/etc/init.d/apache2 restart
  1. 查看网页
    输入以下命令查看服务器IP(需要先安装net-tools)
ifconfig

在其他同一局域网的电脑上打开一个支持webGL的浏览器,输入之前查到的IP地址即可查看发布的网页界面

网页修改

打开html/index.html文件进行接下来的修改

  1. 添加按钮(主要是为了调试html与unity交互正常与否)
    在body中加入以下代码
<button style="margin: 20px; padding: 15px" onclick="回调函数名(形参)">按钮显示的文本</button>

下图是我放置的位置

  1. 声明和赋值实例【十分重要,js调用的关键】
    在script中添加以下代码
var myGameInstance=null;
//其他。。。。。。。。script.onload = () => {createUnityInstance(canvas, config, (progress) => {progressBarFull.style.width = 100 * progress + "%";}).then((unityInstance) => {myGameInstance=unityInstance;//注意加入这一句loadingBar.style.display = "none";fullscreenButton.onclick = () => {unityInstance.SetFullscreen(1);};}).catch((message) => {alert(message);});};
  1. js调用Unity函数
    在script中自定义函数
function update(jointIndex,qx,qy,qz,qw)
{//最近发现只允许调用至多一个形参的函数myGameInstance.SendMessage('GameObject名称','公共函数名',形参)
}

附一:Ubuntu 文件操作常用命令

  1. 复制文件夹
cp A B -r
  1. 删除文件
rm -rf A
  1. 重命名文件
mv A B

附二:Apache 服务器常用操作命令

  1. 查看服务器状态
systemctl status apache2
  1. 开关重启服务器
/etc/init.d apache2 start
/etc/init.d apache2 stop
/etc/init.d apache2 restart

Unity WebGL发布及Ubuntu Apache服务器部署相关推荐

  1. Apache服务器部署(1)

    apache(web服务器)简介: Apache是世界使用排名第一的Web服务器软件.它可以运行在几乎所有广泛使用的计算机平台上,其跨平台和安全性被广泛使用,是最流行的Web服务器端软件之一.它快速. ...

  2. unity WebGL 发布服务后出错

    unity WebGL 发布服务后出错: Unable to parse Build/acWeb.framework.js.unityweb! The file is corrupt, or comp ...

  3. 记录Unity WebGL发布到IIS服务器时遇到的坑

    上次弄页游还是Unity 4.x的时候,用的CentOS 7.Apache,直接SFTP上传到网站目录,浏览器一打开就能正常游玩了.但是没寻思今天,在一个Windows服务器上,使用IIS运行Unit ...

  4. Apache服务器部署(2)

    签名CA证书 环境:server1:172.25.1.1    重置虚拟机       挂载yum源 [root@server1 ~]# yum install mod_ssl -y          ...

  5. ubuntu apache服务器和gitweb服务器搭建

    ubuntu下安装软件十分简单.只需要apt-get install即可,不用自己下载源码,自己编译.这篇文章主要写一下web服务器的搭建,至于gitweb,其实很久以前已经搞了,那时为了更好地推广g ...

  6. Apache服务器部署ASP.NET网站

    资源罗列: apache如何支持asp.net 用 Apache 发布 ASP.NET 网站

  7. Unity webgl发布微信小游戏

    我是unity2019.4版本,采用插件是minigame.202212221540.unitypackage,你可以更新最新版本 appid写你微信开发者上面申请的,cdn路径可以先不写,导出路径英 ...

  8. Ubuntu 新装服务器部署流程

    1.设定时区 rm -f /etc/localtime cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime 2.配置apt-get源 sed -i ...

  9. Apache 服务器存在高危提权漏洞,请升级至最新版本 2.4.39

    百度智能云 云生态狂欢季 热门云产品1折起>>>   Apache HTTP 服务器于4月1日发布了最新的稳定版本 2.4.39,主要是修复安全问题.点此进行下载. 在发布更新不久后 ...

最新文章

  1. Luogu4451 [国家集训队]整数的lqp拆分
  2. linux 文件系统_Linux 虚拟文件系统
  3. JVM_06 垃圾回收相关概念[ 二 ]
  4. OpenGL perpixelgloss逐像素光泽度的实例
  5. mysql ---- innodb-2-索引
  6. PyCharm设置自动换行
  7. 中国企业2017年数据_根据数据,2017年最好的免费在线课程
  8. python3解析库pyquery
  9. exchange server 2013 owa界面语言修改为中文
  10. python实例变量命名规则_python变量命名规则
  11. 戴尔服务器怎么一键重装系统,dell笔记本重装系统步骤
  12. java不小于等于符号怎么打_java 大于等于号怎么打 java编程里面 x大于
  13. 二进制炸弹实验binarybomb 拆弹
  14. Gerrit error:remote: ERROR: The following addresses are currently registered:XXX
  15. godot着色器shader效果收集
  16. 血型(输血-受血)匹配数电设计
  17. 安装打印机共享器(服务器)并用个人电脑连接进行打印
  18. 微信小程序开发之倒计时定时器
  19. 布朗大学的机器人能一笔一划临摹出蒙娜丽莎,还能模仿你的笔迹
  20. (一)什么是流程引擎?为什么学习流程引擎?

热门文章

  1. 患上“吃鸡”选择困难症?准确认识枪械很重要!
  2. java 迭代器的优缺点_java迭代器和for循环优劣详解
  3. nexus上传jar到snapshots
  4. windows安装包删了会有影响吗_Win7系统里的Win10更新安装包如何删除,小编告诉你如何删除...
  5. Android中Fragment的详解和使用。
  6. 11.JavaScript分支语句if、else、elseif、三目运算符
  7. 小学教育如何利用计算机思维,如何在小学计算机教学中培养学生的创新能力
  8. CSS不规则图形画法(clip-path)
  9. 神思者(S.E.N.S) -《故宫三部曲》
  10. linux蓝牙鼠标自动断开,在Ubuntu 18.04系统中蓝牙鼠标连接失败问题的解决