- 一.WebGL不能干的那些事
- 二.注意事项
- 1.播放声音
- 2.跨域
- 3.发布http or https?
- 4.包体大小
- 5.Odin
- 6.T序列化失败
- 三.参考资料
- 四.Build
- 主要步骤
- web.config
- Apache
- IIS
- 手机端去掉提示框
- 全屏
- 加载时间过长
- 页面模板
- 只要进度条不要Logo
- 自定义加载背景图
- 激活嵌入资源
- 五.IIS 部署
- 启用Internet Infomation Services
- 添加程序到IIS
- 六.浏览器设置
- 七.UnityScript与JavaScript通信
1.内置的video player 无法播放。(可以使用AVPro 播放) 2.多线程 3.socket(可以用UnityWebRequest或websocket) 4.不支持dynamic
类型,可以使用object。 5.不支持ComputeShader: SystemInfo.supportsComputeShaders
要去掉AutoPlay
2.跨域参考1 参考2 官网 web.config添加
当发布到https
上时程序中访问http
的都会被改成https,这时候一般就报错了。。。
注意工程中尽量不用Resources
文件夹,不然打包的时候会导致包体过大。因为放在该文件夹下的东西都会被打包。
有的类型在WebGL平台并不支持序列化,如果你使用了Odin就需要在打包前生成AOT
:
T序列化失败,System.Reflection.Emit.DynamicMethod::.ctor
把序列化工具换成Json .Net For Unity
三.参考资料hi,WebGL Unity 发布WebGL注意事项 Unity WebGL 官方教程 Unity WebGL官方教程翻译 发布后打不开 Unity WebGL游戏 官方WebGL Tiny IIS的搭建 别个的笔记 问题总结
四.Build空场景build耗时~142s 测试demo
主要步骤需要在index.html同级目录下添加web.config
配置文件。 需要根据部署的服务器决定:
web.config
后缀改成.htaccess
Gzip版本
:
AddType application/octet-stream .unityweb
AddEncoding gzip .unityweb
AddType application/wasm .wasm
AddEncoding gzip .wasm
AddOutputFilterByType DEFLATE application/wasm
Brotli版本
:
AddEncoding br .unityweb
RemoveType .wasm
AddType application/wasm .wasm
RemoveType .unityweb
AddType application/octet-stream .unityweb
IIS
首先安装URL Rewrite
!
手机端去掉提示框
在手机端打开wegl项目会弹出不支持webgl的提示框,不想要的话可以把UnityLoader.js
文件内的提示框代码改下(line:2041): 修改前代码
compatibilityCheck: function(e, t, r) {
UnityLoader.SystemInfo.hasWebGL ? UnityLoader.SystemInfo.mobile ? e.popup("Please note that Unity WebGL is not currently supported on mobiles. Press OK if you wish to continue anyway.", [{
text: "OK",
callback: t
}]) : ["Edge", "Firefox", "Chrome", "Safari"].indexOf(UnityLoader.SystemInfo.browser) == -1 ? e.popup("Please note that your browser is not currently supported for this Unity WebGL content. Press OK if you wish to continue anyway.", [{
text: "OK",
callback: t
}]) : t() : e.popup("Your browser does not support WebGL", [{
text: "OK",
callback: r
}])
},
修改后
compatibilityCheck: function(e, t, r) {
UnityLoader.SystemInfo.hasWebGL ? ["Edge", "Firefox", "Chrome", "Safari"].indexOf(UnityLoader.SystemInfo.browser) == -1 ? e.popup("Please note that your browser is not currently supported for this Unity WebGL content. Press OK if you wish to continue anyway.", [{
text: "OK",
callback: t
}]) : t() : e.popup("Your browser does not support WebGL", [{
text: "OK",
callback: r
}])
},
全屏
index.html
修改如下:
Unity WebGL Player | Pudong
var gameInstance = UnityLoader.instantiate("gameContainer", "Build/build.json", {
onProgress: UnityProgress
});
body {
overflow: scroll;
overflow-x: hidden;
overflow-y: hidden;
}
function ChangeCanvas() {
document.getElementById("gameContainer").style.width = window.innerWidth + "px";
document.getElementById("gameContainer").style.height = window.innerHeight + "px";
document.getElementById("#canvas").style.width = window.innerWidth + "px";
document.getElementById("#canvas").style.height = window.innerHeight + "px";
}
以上修改只能做到页面最大化,如果要全屏可以手动F11或者添加其他代码
1.使用Gzip压缩格式
模板demo
用以下内容替换UnityProgress.js
function UnityProgress(gameInstance, progress) {
if (!gameInstance.Module)
return;
if (!gameInstance.progress) {
gameInstance.progress = document.createElement("div");
gameInstance.progress.className = "progress " + gameInstance.Module.splashScreenStyle;
gameInstance.progress.empty = document.createElement("div");
gameInstance.progress.empty.className = "empty";
gameInstance.progress.appendChild(gameInstance.progress.empty);
gameInstance.progress.full = document.createElement("div");
gameInstance.progress.full.className = "full";
gameInstance.progress.appendChild(gameInstance.progress.full);
gameInstance.container.appendChild(gameInstance.progress);
}
gameInstance.progress.full.style.width = (100 * progress) + "%";
gameInstance.progress.empty.style.width = (100 * (1 - progress)) + "%";
if (progress == 1)
gameInstance.progress.style.display = "none";
}
Unity发布WebGL时如何修改、删除默认的载入进度条
自定义加载背景图如下所示把黑色的背景
换成了图片!!! 方法概况:直接把Logo换成想要的背景图,然后在css中修改尺寸即可
{(>A
最近更新
- 深拷贝和浅拷贝的区别(重点)
- 【Vue】走进Vue框架世界
- 【云服务器】项目部署—搭建网站—vue电商后台管理系统
- 【React介绍】 一文带你深入React
- 【React】React组件实例的三大属性之state,props,refs(你学废了吗)
- 【脚手架VueCLI】从零开始,创建一个VUE项目
- 【React】深入理解React组件生命周期----图文详解(含代码)
- 【React】DOM的Diffing算法是什么?以及DOM中key的作用----经典面试题
- 【React】1_使用React脚手架创建项目步骤--------详解(含项目结构说明)
- 【React】2_如何使用react脚手架写一个简单的页面?