热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

unityweb端h5记录

title:unity-web端h5记


title: unity-web端h5记录
categories: Unity3d
tags: [unity, web, h5]
date: 2023-02-23 17:00:53
comments: false
mathjax: true
toc: true


unity-web端h5记录



前篇


  • 5款常用的html5游戏引擎以及优缺点分析 - https://imgtec.eetrend.com/blog/2022/100557792.html
  • Unity WebGL 开发指北(完全篇) - https://zhuanlan.zhihu.com/p/475307249



平台适配


文件 io 适配


  • web 请求资源, 全都需要异步加载



构建和运行 WebGL 项目


  • 构建和运行 WebGL 项目 - https://docs.unity3d.com/cn/2021.2/Manual/webgl-building.html



使用 nginx 作为文件服务器


  • 下载地址: http://nginx.org/en/download.html

使用

  • 启动

    C:\server\nginx-1.0.2>start nginx
    or
    C:\server\nginx-1.0.2>nginx.exe

  • 停止

    C:\server\nginx-1.0.2>nginx.exe -s stop

    C:\server\nginx-1.0.2>nginx.exe -s quit

  • 重新载入配置

    C:\server\nginx-1.0.2>nginx.exe -s reload

  • 重新打开日志文件

    C:\server\nginx-1.0.2>nginx.exe -s reopen

  • 查看版本

    C:\server\nginx-1.0.2>nginx -v




平台判断


  • 编译宏 https://docs.unity3d.com/Manual/PlatformDependentCompilation.html

    #if UNITY_WEBGLLogUtil.D("--- UNITY_WEBGL ");
    #endif

  • 运行时

    Application.platform == RuntimePlatform.WebGLPlayer




http

使用 best http, 版本最新即可, 如: 2.8.2



websocket

使用 best http, 版本最新即可, 如: 2.8.2

  • Unity下使用BestHTTP插件进行Http和WebSocket通信 - https://blog.csdn.net/foupwang/article/details/104725423



踩坑


未开启 gz


  • 报错

    Unable to parse Build/aaa.framework.js.gz! This can happen if build compression was enabled but web server hosting the content was misconfigured to not serve the file with HTTP Response Header "Content-Encoding: gzip" present. Check browser Console and Devtools Network tab to debug.

官方推荐的是 使用 nginx, 参考: https://docs.unity3d.com/cn/2021.2/Manual/webgl-server-configuration-code-samples.html

  • http {# 增加一个 server 配置server {listen 8811; server_name localhost;root C:/Users/wilker/Desktop/aaa; # unity 打出的 h5 包index index.html# location / {# root html;# index index.html index.htm;# }error_page 500 502 503 504 /50x.html;location = /50x.html {root html;}######################################### Add the following config within http server configuration# ...# On-disk Brotli-precompressed data files should be served with compression enabled:location ~ .+\.(data|symbols\.json)\.br$ {# Because this file is already pre-compressed on disk, disable the on-demand compression on it.# Otherwise nginx would attempt double compression.gzip off;add_header Content-Encoding br;default_type application/octet-stream;}# On-disk Brotli-precompressed Javascript code files:location ~ .+\.js\.br$ {gzip off; # Do not attempt dynamic gzip compression on an already compressed fileadd_header Content-Encoding br;default_type application/Javascript;}# On-disk Brotli-precompressed WebAssembly files:location ~ .+\.wasm\.br$ {gzip off; # Do not attempt dynamic gzip compression on an already compressed fileadd_header Content-Encoding br;# Enable streaming WebAssembly compilation by specifying the correct MIME type for# Wasm files.default_type application/wasm;}# On-disk gzip-precompressed data files should be served with compression enabled:location ~ .+\.(data|symbols\.json)\.gz$ {gzip off; # Do not attempt dynamic gzip compression on an already compressed fileadd_header Content-Encoding gzip;default_type application/octet-stream;}# On-disk gzip-precompressed Javascript code files:location ~ .+\.js\.gz$ {gzip off; # Do not attempt dynamic gzip compression on an already compressed fileadd_header Content-Encoding gzip;default_type application/Javascript;}# On-disk gzip-precompressed WebAssembly files:location ~ .+\.wasm\.gz$ {gzip off; # Do not attempt dynamic gzip compression on an already compressed fileadd_header Content-Encoding gzip;# Enable streaming WebAssembly compilation by specifying the correct MIME type for# Wasm files.default_type application/wasm;}}
    }




移动设备不支持


  • 报错

    WebGL builds are notsupported on mobile devices.

据说不用管这个



中文显示


  • a



http 请求


原生端旧的 best http 插件报错

Invoking error handler due to
ReferenceError: Runtime is not defined
at XMLHttpRequest.http_onload (http://localhost:8811/Build/aaa.framework.js.gz:3:85864)

  • 解决办法: 升级 best http 插件到 2.8.2+ 即可.

UnityWebRequest 请求报错

exception thrown: TypeError: Cannot set properties of undefined (setting '1'),TypeError: Cannot set properties of undefined (setting '1')at _JS_WebRequest_Create (http://localhost:8811/Build/slotsweb.framework.js.gz:3:73755)at http://localhost:8811/Build/slotsweb.wasm.gz:wasm-function[47545]:0x10870bf

  • 参考: https://forum.unity.com/threads/cannot-set-properties-of-undefined-setting-1-when-running-a-unitywebrequest.1248445/
  • 暂时不去解决, 采用升级 best http 插件的办法



推荐阅读
  • Nginx使用AWStats日志分析的步骤及注意事项
    本文介绍了在Centos7操作系统上使用Nginx和AWStats进行日志分析的步骤和注意事项。通过AWStats可以统计网站的访问量、IP地址、操作系统、浏览器等信息,并提供精确到每月、每日、每小时的数据。在部署AWStats之前需要确认服务器上已经安装了Perl环境,并进行DNS解析。 ... [详细]
  • 本文由编程笔记小编整理,主要介绍了使用Junit和黄瓜进行自动化测试中步骤缺失的问题。文章首先介绍了使用cucumber和Junit创建Runner类的代码,然后详细说明了黄瓜功能中的步骤和Steps类的实现。本文对于需要使用Junit和黄瓜进行自动化测试的开发者具有一定的参考价值。摘要长度:187字。 ... [详细]
  • ShiftLeft:将静态防护与运行时防护结合的持续性安全防护解决方案
    ShiftLeft公司是一家致力于将应用的静态防护和运行时防护与应用开发自动化工作流相结合以提升软件开发生命周期中的安全性的公司。传统的安全防护方式存在误报率高、人工成本高、耗时长等问题,而ShiftLeft提供的持续性安全防护解决方案能够解决这些问题。通过将下一代静态代码分析与应用开发自动化工作流中涉及的安全工具相结合,ShiftLeft帮助企业实现DevSecOps的安全部分,提供高效、准确的安全能力。 ... [详细]
  • 本文介绍了Java调用Windows下某些程序的方法,包括调用可执行程序和批处理命令。针对Java不支持直接调用批处理文件的问题,提供了一种将批处理文件转换为可执行文件的解决方案。介绍了使用Quick Batch File Compiler将批处理脚本编译为EXE文件,并通过Java调用可执行文件的方法。详细介绍了编译和反编译的步骤,以及调用方法的示例代码。 ... [详细]
  • 原文地址:https:www.cnblogs.combaoyipSpringBoot_YML.html1.在springboot中,有两种配置文件,一种 ... [详细]
  • 本文介绍了在多平台下进行条件编译的必要性,以及具体的实现方法。通过示例代码展示了如何使用条件编译来实现不同平台的功能。最后总结了只要接口相同,不同平台下的编译运行结果也会相同。 ... [详细]
  • Linux如何安装Mongodb的详细步骤和注意事项
    本文介绍了Linux如何安装Mongodb的详细步骤和注意事项,同时介绍了Mongodb的特点和优势。Mongodb是一个开源的数据库,适用于各种规模的企业和各类应用程序。它具有灵活的数据模式和高性能的数据读写操作,能够提高企业的敏捷性和可扩展性。文章还提供了Mongodb的下载安装包地址。 ... [详细]
  • Android系统源码分析Zygote和SystemServer启动过程详解
    本文详细解析了Android系统源码中Zygote和SystemServer的启动过程。首先介绍了系统framework层启动的内容,帮助理解四大组件的启动和管理过程。接着介绍了AMS、PMS等系统服务的作用和调用方式。然后详细分析了Zygote的启动过程,解释了Zygote在Android启动过程中的决定作用。最后通过时序图展示了整个过程。 ... [详细]
  • Java 11相对于Java 8,OptaPlanner性能提升有多大?
    本文通过基准测试比较了Java 11和Java 8对OptaPlanner的性能提升。测试结果表明,在相同的硬件环境下,Java 11相对于Java 8在垃圾回收方面表现更好,从而提升了OptaPlanner的性能。 ... [详细]
  • 如何实现JDK版本的切换功能,解决开发环境冲突问题
    本文介绍了在开发过程中遇到JDK版本冲突的情况,以及如何通过修改环境变量实现JDK版本的切换功能,解决开发环境冲突的问题。通过合理的切换环境,可以更好地进行项目开发。同时,提醒读者注意不仅限于1.7和1.8版本的转换,还要适应不同项目和个人开发习惯的需求。 ... [详细]
  • 一次上线事故,30岁+的程序员踩坑经验之谈
    本文主要介绍了一位30岁+的程序员在一次上线事故中踩坑的经验之谈。文章提到了在双十一活动期间,作为一个在线医疗项目,他们进行了优惠折扣活动的升级改造。然而,在上线前的最后一天,由于大量数据请求,导致部分接口出现问题。作者通过部署两台opentsdb来解决问题,但读数据的opentsdb仍然经常假死。作者只能查询最近24小时的数据。这次事故给他带来了很多教训和经验。 ... [详细]
  • Linux下安装免费杀毒软件ClamAV及使用方法
    本文介绍了在Linux系统下安装免费杀毒软件ClamAV的方法,并提供了使用该软件更新病毒库和进行病毒扫描的指令参数。同时还提供了官方安装文档和下载地址。 ... [详细]
  • Tomcat安装与配置教程及常见问题解决方法
    本文介绍了Tomcat的安装与配置教程,包括jdk版本的选择、域名解析、war文件的部署和访问、常见问题的解决方法等。其中涉及到的问题包括403问题、数据库连接问题、1130错误、2003错误、Java Runtime版本不兼容问题以及502错误等。最后还提到了项目的前后端连接代码的配置。通过本文的指导,读者可以顺利完成Tomcat的安装与配置,并解决常见的问题。 ... [详细]
  • Mono为何能跨平台
    概念JIT编译(JITcompilation),运行时需要代码时,将Microsoft中间语言(MSIL)转换为机器码的编译。CLR(CommonLa ... [详细]
  • 初识java关于JDK、JRE、JVM 了解一下 ... [详细]
author-avatar
手机用户2702935165
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有