栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 游戏开发 > Unity3D

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

Unity3D 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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

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 "/Build/.htaccess"
# NOTE: "mod_mime" Apache module must be enabled for this configuration to work.


# 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


  1. 重启服务器
/etc/init.d/apache2 restart
  1. 查看网页
    输入以下命令查看服务器IP(需要先安装net-tools)
ifconfig

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

网页需改

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

  1. 添加按钮
    在body中加入以下代码

下图是我放置的位置

  1. 声明和赋值实例【】
    在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名称','公共函数名',形参1,...)
}
附一: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
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/899632.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号