zombieyang / puerts_unity_webgl_demo

在Unity里用Typescript写小游戏/Web游戏
BSD 3-Clause "New" or "Revised" License
181 stars 63 forks source link

[unity] 在浏览器运行报错:exception thrown: Error: please use Puerts.WebGL.GetBrowserEnv() to create JsEnv,Error: please use Puerts.WebGL.GetBrowserEnv() to create JsEnv #25

Closed zhuangce closed 2 years ago

zhuangce commented 2 years ago

error log | 日志或报错信息

在修改unity playersettting 后 也可能报这个错 exception thrown: TypeError: Cannot read properties of undefined (reading 'inited'),TypeError: Cannot read properties of undefined (reading 'inited'). 我定位到的webgl.frameworks.js代码 :

function _GetApiLevel() { var global = typeof global != "undefined" ? global : window; if (!global.PuertsWebGL.inited) { throw new Error("please use Puerts.WebGL.GetBrowserEnv() to create JsEnv"); }

context | 编译/运行环境

unity2021.2 /Chrome(v100+)浏览器

how to reproduce | 复现步骤

  1. 编译项目
  2. 用node.js运行服务
  3. 在Chrome打开项目

more | 其他

根据错误描述去代码里添加puerts.webgl.getborwerenv() ,却没有这样的类

zombieyang commented 2 years ago

https://github.com/zombieyang/puerts_unity_webgl_demo/blob/master/package/Runtime/WebGL.cs#L10 那个类就在这,不太可能没有,是不是build target不对?或者不小心把manifest.json里对package的引用删掉了?

zhuangce commented 2 years ago

https://github.com/zombieyang/puerts_unity_webgl_demo/blob/master/package/Runtime/WebGL.cs#L10 那个类就在这,不太可能没有,是不是build target不对?或者不小心把manifest.json里对package的引用删掉了?

感谢回复, 我通过重新导入一次webgl package 解决了报错,之前应该是我在包管理器中下载了但是unity并没有识别到。

zombieyang commented 2 years ago

优化了一下错误信息,后面类似的问题应该就能看到正确的错误信息而不是那个 reading 'inited'了