- With this project. Unity Puer's JS Code will run in the v8 of browser instead of v8/quickjs in WebAssembly.
- 通过该项目的支持,Unity puer的JS代码会运行在宿主JS引擎里,而不是运行在编译为WASM的JS解释器里。
-
High Efficiency | 开发很快
- all the JS file can run in browser directly. you dont have to rebuild the unity project after JS script is modified.
- 所有JS逻辑文件都可以直接在宿主JS环境跑,因此你不需要在每次改完脚本代码后重新构建unity项目了。
-
Fast | 执行很快
-
with the JIT in browser's v8. Puer Webgl has a huge execute performance advantage.
-
因为在这套架构下,JS是运行在宿主JS环境下的,有JIT的支持,因此相比Lua脚本方案,在执行性能上有碾压性的性能优势。
100k fibonacci(12) xLua WebGL 6200ms Puerts WebGL 165ms
-
-
PuerTS is not only developed for WebGL game development. It allows you to write Typescript in Unity native game too.
-
PuerTS并不是只针对WebGL游戏开发的框架,它本身支持你在原生Unity中编写Typescript
-
So. the guidance below is assumed that you already know something about puerts. Or you can learn about it in Tencent/puerts
-
下列指引都是假设你已经有对PuerTS本身足够的了解。您可以先在 Tencent/puerts 获得一些知识再往下进行。
- start a http server in
build
directory. you can quickly try these 4 demo which is built by Unity2019. - 在build目录启动一个httpserver,通过网页访问即可看到4个demo的效果,它们是Unity2019编译产生的。
- Simple Rotate Demo | 简单旋转demo
- Basketball Game Demo | 篮球小游戏demo
- UnitTest
- Compare with XLua WebGL | 和 xLua WebGL 进行fibonacci 性能对比测试demo
- Open any project in
projects
| 打开projects
下的任意项目 - Click
puerts-webgl/install
in the Menu | 点击puerts-webgl/install
- Do Unity WebGL Build | 执行Unity的WebGL Build
- Click
puerts-webgl/build for browser
following the tips in console | 根据命令行提示,点击puerts-webgl/build for browser
将JS拷贝到构建目录 - append these code befoew
</head>
in index.html built by Unity: | 将下述代码放到index.html的前
<script src="./puerts-runtime.js"></script>
<script src="./puerts_browser_js_resources.js"></script>
-
Install puerts first (by upm). then: | 首先安装puerts (注意要用upm的方式)。随后:
Add from OpenUPM | available in 2018+
你可按照OpenUPM所支持的方式安装该包:https://openupm.com/packages/com.tencent.puerts.webgl/
Add from GitHub | available in 2019.4+
You can add it directly from GitHub on Unity 2019.4+. Note that you won't be able to receive updates through Package Manager this way, you'll have to update manually.
- open Package Manager
- click +
- select Add from Git URL
- paste
https://github.com/zombieyang/puerts_unity_webgl_demo.git?path=/package
- click Add
- 运作原理(how this work?)
Puerts的WebGL版本是利用Unity官方提供的Unity代码与浏览器脚本交互的功能,对Puerts中使用到的PuertsDLL.cs
里的API通过JS一一进行实现。关键代码位于Assets/Plugins/puerts.jslib
以及puerts-webgl/PuertsDLLMock
。
Unable to parse Build/H5.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.
- set
Player Settings > Publish Settings > Compression Format
toDisabled
. delete your previous build and rebuild. - 将
Player Settings > Publish Settings > Compression Format
设为Disabled
。删掉你上一次的构建产物,然后重新构建。
- generally, you can check the resources loading in your game. make sure that you disable the Unity builtin caching.
- 一般来说,你可以检查一下你游戏的资源加载流程,确认关掉了资源加载的cache。
3. I'm going to migrate my old PuerTS Game to this. How can I do this ? | 我需要将我过往的PuerTS游戏迁移过来,有什么需要注意的吗?
- If you are on 1.4+ of PuerTS, nothing is needed to do for migrate.
- 如果你使用的是1.4+版本的PuerTS,那么没什么太多需要注意的。但如果是1.3以下,请关注 这篇wiki
(如果过期了,可到puerts官方群QQ私聊我)