【unity发布webgl】遇到的问题和解决办法

2023-10-29

1.发布部署出来的链接放到手机上测试。
ios:20秒读条然后闪退;vivo:9秒读条闪退;小米:15秒进入
然鹅,资料只有130kb的图片。

2.报这个警告,修改Build文件夹里的UnityLoader.js取消
移动端展示弹出提示框,点击OK后继续打开webgl
please note the unity webgl is not currently supported on mobiles.press ok if you wish to continue anyway.
请注意,手机目前不支持unity webgl。如果仍要继续,请按ok。
修改UnityLoader.js:

compatibilityCheck:function(e,t,r){
    UnityLoader.SystemInfo.hasWebGL?
        UnityLoader.SystemInfo.mobile?
            t()
            :["Firefox","Chrome","Safari"].indexOf(UnityLoader.SystemInfo.browser)==-1?
                t()
                :t()
        :e.popup("Your browser does not support WebGL",[{text:"OK",callback:r}])
    },
    Blobs:{},loa...(省略)

请添加图片描述
3.自适应屏幕修改和手机端强制横屏index.html
因为浏览器的分辨率不一样,所以我上面的button都不在原位置,而且分辨率小的浏览器显示的画布都不全,就得做自适应。
还有PC端是横版的,要是手机端是竖版的就得做两套UI,判断webgl是运行在PC端还是手机端,然后jslib本地插件从浏览器获取屏幕分辨率数据再把数据传回unity再通过screen.Resolution()函数设置画布的大小有点麻烦,我们直接就手机端强制横屏了。(测试最新判断unitywebgl运行在PC还是手机端的方法报了五个错打出来的空包,老办法PC是cube 手机端是sphere还是可以的)

<!DOCTYPE html>
<html lang="en-us">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Unity WebGL Player | TestConnection</title>
    <link rel="shortcut icon" href="TemplateData/favicon.ico">
    <link rel="stylesheet" href="TemplateData/style.css">
    <script src="TemplateData/UnityProgress.js"></script>
    <script src="Build/UnityLoader.js"></script>
    <script>
      var gameInstance = UnityLoader.instantiate("gameContainer", "Build/num3.json", {onProgress: UnityProgress});
      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";
      }
    </script>
  </head>
  <body onResize="ChangeCanvas()">
    <div class="webgl-content">
      <div id="gameContainer" style="width: 100%; height: 100%"></div>
    </div>

     <style type="text/css">
     
      @media screen and (orientation: portrait) { /*竖屏*/
        .webgl-content {position:absolute; width: 100vh; height: 100vw; top: 0; left: 100vw; -webkit-transform: rotate(90deg); -moz-transform: rotate(90deg); -ms-transform: rotate(90deg); transform: rotate(90deg); transform-origin: 0% 0%; } 
      }

      @media screen and (orientation: landscape) {
          html{
              width : 100vw;
              height : 100vh;
          }
          body{
              width : 100vw;
              height : 100vh;
          }
          .webgl-content{
              width : 100vw;
              height : 100vh;
          }
      }
    </style>
  </body>
</html>
.webgl-content * {border: 0; margin: 0; padding: 0}

/*添加 width: 100%; height: 100%;*/
.webgl-content {position: absolute; top: 50%; left: 50%; width: 100%; height: 100%; -webkit-transform: translate(-50%, -50%); transform: translate(-50%, -50%);}

.webgl-content .logo, .progress {position: absolute; left: 50%; top: 50%; -webkit-transform: translate(-50%, -50%); transform: translate(-50%, -50%);}
.webgl-content .logo {background: url('progressLogo.Light.png') no-repeat center / contain; width: 154px; height: 130px;}
.webgl-content .progress {height: 18px; width: 141px; margin-top: 90px;}
.webgl-content .progress .empty {background: url('progressEmpty.Light.png') no-repeat right / cover; float: right; width: 100%; height: 100%; display: inline-block;}
.webgl-content .progress .full {background: url('progressFull.Light.png') no-repeat left / cover; float: left; width: 0%; height: 100%; display: inline-block;}

.webgl-content .logo.Dark {background-image: url('progressLogo.Dark.png');}
.webgl-content .progress.Dark .empty {background-image: url('progressEmpty.Dark.png');}
.webgl-content .progress.Dark .full {background-image: url('progressFull.Dark.png');}

/*如果你要保存 footer模块, 然后又要让footer显示在最顶部,这样处理*/
.webgl-content .footer {margin-top: -45px; margin-left: 5px; margin-right: 5px; z-index: 1; position: relative; height: 38px; line-height: 38px; font-family: Helvetica, Verdana, Arial, sans-serif; font-size: 18px;} 
.webgl-content .footer .webgl-logo, .title, .fullscreen {height: 100%; display: inline-block; background: transparent center no-repeat;} 
.webgl-content .footer .webgl-logo {background-image: url('webgl-logo.png'); width: 204px; float: left;}
.webgl-content .footer .title {margin-right: 10px; float: right;}
.webgl-content .footer .fullscreen {background-image: url('fullscreen.png'); width: 38px; float: right;}

4.logo替换成gif进度加载的样式、背景图替换

.webgl-content * {border: 0; margin: 0; padding: 0}
.webgl-content {position: absolute; top: 50%; left: 50%; -webkit-transform: translate(-50%, -50%); transform: translate(-50%, -50%);}

.webgl-content .logo, .progress {position: absolute; left: 50%; top: 50%; -webkit-transform: translate(-50%, -50%); transform: translate(-50%, -50%);}
.webgl-content .logo {background: url('person.gif') no-repeat center / contain; width: 154px; height: 130px;}
.webgl-content .progress {height: 18px; width: 141px; margin-top: 90px;}
.webgl-content .progress .empty {background: url('progressEmpty.Light.png') no-repeat right / cover; float: right; width: 100%; height: 100%; display: inline-block;}
.webgl-content .progress .full {background: url('progressFull.Light.png') no-repeat left / cover; float: left; width: 0%; height: 100%; display: inline-block;}

.webgl-content .logo.Dark {background-image: url('person.gif');}
.webgl-content .progress.Dark .empty {background-image: url('progressEmpty.Dark.png');}
.webgl-content .progress.Dark .full {background-image: url('progressFull.Dark.png');}

.webgl-content .footer {margin-top: 5px; height: 38px; line-height: 38px; font-family: Helvetica, Verdana, Arial, sans-serif; font-size: 18px;}
.webgl-content .footer .webgl-logo, .title, .fullscreen {height: 100%; display: inline-block; background: transparent center no-repeat;}
.webgl-content .footer .webgl-logo {background-image: url('webgl-logo.png'); width: 204px; float: left;}
.webgl-content .footer .title {margin-right: 10px; float: right;}
.webgl-content .footer .fullscreen {background-image: url('fullscreen.png'); width: 38px; float: right;}

在这里插入图片描述
背景图在webgl.json里改,再替换unityloader.js

{
"companyName": "DefaultCompany",
"productName": "HidedenObject",
"productVersion": "1.0",
"dataUrl": "webgl.data.unityweb",
"wasmCodeUrl": "webgl.wasm.code.unityweb",
"wasmFrameworkUrl": "webgl.wasm.framework.unityweb",
"graphicsAPI": ["WebGL 2.0","WebGL 1.0"],
"webglContextAttributes": {"preserveDrawingBuffer": false},
"splashScreenStyle": "Dark",
"backgroundUrl":"bg.jpg",
//"backgroundColor": "#231F20",
"cacheControl": {"default": "must-revalidate"},
"developmentBuild": false,
"multithreading": false,
"unityVersion": "2019.4.35f1c1"
}

在这里插入图片描述

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

【unity发布webgl】遇到的问题和解决办法 的相关文章

  • javaWeb学习笔记 --- Html

    HTML html是超文本标记语言 它规定了自己的语法规则 用来表示比 文本 更丰富的意义 比如图片 表格 链接等 目前互联网上的绝大部分网页都是使用HTML编写的 html的结构

随机推荐

  • 前端ssh自动部署

    1 先安装两依赖包 archiver 是用来压缩dist文件 node ssh用来和ssh链接登录以及命令的执行 npm install node ssh archiver save 2 在根目录建一个文件 我这里给它取名upload js
  • linux查找目录

    要在Linux中查找目录 可以使用find命令 下面是查询目录的几个示例 1 查找当前目录下所有子目录 find type d 2 在指定路径下查找目录 find path to directory type d 3 查找以特定名称开头的目
  • restful风格API

    一 什么是API API Application Programming Interface 应用程序编程接口 是一些预先定义的函数 目的是提供应用程序与开发人员基于某软件或硬件得以访问一组例程的能力 而又无需访问源码 或理解内部工作机制的
  • D0002-数据类型转换与运算符

    数据类型转换 1 隐式 自动 类型转换 从数据类型小的到数据类型大的转换 都是数字型的 布尔类型不参与 byte lt short lt int lt long lt float lt double char lt int lt long
  • Netty概述

    1 Netty 概述 1 1 Netty 简介 Netty 官网上可以看到最权威的介绍 Netty 是一个异步事件驱动的网络应用程序框架 用于快速开发可维护的高性能服务器和客户端 Netty 是一个 NIO 客户机 服务器框架 它支持快速
  • 判断正整数的正则表达式

    正数的正则表达式 包括0 小数保留两位 0 1 d 1 2 1 9 d 1 d 1 2 1 9 d 0 正数的正则表达式 不包括0 小数保留两位 0 1 d 1 2 1 9 d 1 d 1 2 1 9 d 正整数的正则表达式 包括0 0 1
  • OSI和TCP/IP

    1 OSI和TCP IP 1 1 模型对比 OSI七层 TCP IP五层 TCP IP四层 应用层 应用层 应用层 表示层 会话层 传输层 传输层 传输层 网络层 网络层 网络层 数据链路层 数据链路层 网络接口层 物理层 物理层 1 2
  • i5十代不能装win7系统_戴尔台式机i5十代CPU,3991或3881,Win10改win7方法

    戴尔台式机3991或3881 Win10改win7方法如下为精简步聚 希望能给大家有所帮助 电脑的配置为i5 10500十代CPU DDR4代内存 一 WinPE要求 小兵PE2020版 里面有注入USB3 X及NVME驱动和小兵系统安装软
  • C语言中有符号和无符号的区别(signed与unsigned)

    include
  • Maven构建与管理项目(三)

    Maven构建与管理项目 三 Maven与Eclipse整合 安装Maven插件 下载下来的maven插件如下图所示 插件存放的路径是 E MavenProject Maven2EclipsePlugin 进入到eclipse中的dropi
  • 使用langchain+chatGPT搭建自有知识库问答机器人

    前言 自去年年底OpenAI发布ChatGPT以来 大型语言模型在人工智能领域掀起了一股热潮 随后 各家公司纷纷推出自己的大型语言模型 如百度的文心一言 讯飞的星火大模型等 在这个过程中 文本转图片和文本转视频等相关领域也备受关注 然而 很
  • C++泛型编程——模板,容器实现

    泛型编程 模板技术 模板实例化 模板的使用 模板参数 模板特化 函数模板特化 类模板特化 容器适配器 分离编译模式 泛型编程 泛型编程是编写和类型无关的逻辑代码 是代码复用的另一种手段 模板是实现泛型编程的一种技术 以往要编写一个通用的函数
  • mysql常用语句总结(一)

    连接数据库 mysql uroot padmin 使用数据库 use 库名 查看数据库列表 show databases 创建数据库 create database 数据库名称 删除数据库 drop database 数据库名称 查看当前数
  • javaEE和javaweb的区别

    JavaEE JavaEE 概念 Java EE Java 平台企业版 Java Platform Enterprise Edition 之前称为Java 2 Platform Enterprise Edition J2EE 2018年3月
  • OSI七层参考模型与5G协议

    计算机网络参考模型与5G协议 目录 计算机网络参考模型与5G协议 分层思想 OSI七层参考模型 OSI模型vsTCP IP模型 TCP IP协议组成 数据通信4要素 ARP工作原理 ICMP 数据封装过程 解封装过程 客户端和服务器的关系
  • 关于warning: #1295-D: Deprecated declaration (某函数) - give arg type的解决

    问题 使用keil5编写STM32单片机程序时 在头文件中声明了一个无参数的函数 并且没有返回值 出现warning 解决 在声明函数的括号中添加void 警告消除
  • Python异步请求:深入理解异步编程模型

    Python异步请求 深入理解异步编程模型 引言 随着现代应用程序对性能和响应速度的要求越来越高 异步任务请求成为了Python开发中重要的技术之一 本文将深入探讨Python中的异步任务请求的原理和用法 并提供详细的代码示例 帮助读者更好
  • 多元函数的极值matlab,利用MATLAB求多元函数的极值(2)

    利用MATLAB求多元函数的极值分两种情况 1 无约束条件 2 有约束条件 2 有约束条件下求极小值的方法 假设多变量非线性函数的数学模型为 min f x c x lt 0 ceq x 0 A x lt b Aeq x lt x lt b
  • python学习2.1列表

    一 初试列表 与C中的数组类似 1 列表的定义和输出 约定俗成 用 引起列表 eg 输入 band the beatles oasis eagles print band 输出 the beatles oasis eagles 2 列表元素
  • 【unity发布webgl】遇到的问题和解决办法

    1 发布部署出来的链接放到手机上测试 ios 20秒读条然后闪退 vivo 9秒读条闪退 小米 15秒进入 然鹅 资料只有130kb的图片 2 报这个警告 修改Build文件夹里的UnityLoader js取消 移动端展示弹出提示框 点击