Puerts WebGL Unity introduction | 简介 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解释器里。 Advantage | 优势 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 QuickStart | 开始 have a try | 体验一下效果 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 How to rebuild | 如何重新构建? 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 in your own project | 在你自己的项目中安装 Install puerts first. then: 首先安装puerts。随后: 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 About WeChat minigame | 关于微信小游戏? 点我 Dependent | 依赖 because of the dependent with WeakRef and FinalizationRegistry. this project is available in the environment below. 因为大量使用到了WeakRef和FinalizationRegistryAPI。该功能在以下环境下可用: V8 8.4+(Chrome 84+) OR v8 7.4+(Chrome 84+) with --harmony-weak-refs iOS Safari 14.5+/OSX Safari 14.1+ WeChat Minigame | 微信小游戏 How to contrib 运作原理(how this work?) Puerts的WebGL版本是利用Unity官方提供的Unity代码与浏览器脚本交互的功能,对Puerts中使用到的PuertsDLL.cs里的API通过JS一一进行实现。关键代码位于Assets/Plugins/puerts.jslib以及puerts-webgl/PuertsDLLMock。 未来还有以下工作要做(TODO): 测试2021下bigint表现
zombieyang/puerts_unity_webgl_demo
Puerts WebGL Unity
introduction | 简介
Advantage | 优势
with the JIT in browser's v8. Puer Webgl has a huge execute performance advantage.
因为在这套架构下,JS是运行在宿主JS环境下的,有JIT的支持,因此相比Lua脚本方案,在执行性能上有碾压性的性能优势。
QuickStart | 开始
have a try | 体验一下效果
build
directory. you can quickly try these 4 demo which is built by Unity2019.How to rebuild | 如何重新构建?
projects
| 打开projects
下的任意项目puerts-webgl/install
in the Menu | 点击puerts-webgl/install
puerts-webgl/build for browser
following the tips in console | 根据命令行提示,点击puerts-webgl/build for browser
将JS拷贝到构建目录</head>
in index.html built by Unity: | 将下述代码放到index.html的前install in your own project | 在你自己的项目中安装
Install puerts first. then:
首先安装puerts。随后:
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.
https://github.com/zombieyang/puerts_unity_webgl_demo.git?path=/package
About WeChat minigame | 关于微信小游戏?
点我
Dependent | 依赖
WeakRef
andFinalizationRegistry
. this project is available in the environment below.WeakRef
和FinalizationRegistry
API。该功能在以下环境下可用:V8 8.4+(Chrome 84+)
ORv8 7.4+(Chrome 84+) with --harmony-weak-refs
How to contrib
Puerts的WebGL版本是利用Unity官方提供的Unity代码与浏览器脚本交互的功能,对Puerts中使用到的
PuertsDLL.cs
里的API通过JS一一进行实现。关键代码位于Assets/Plugins/puerts.jslib
以及puerts-webgl/PuertsDLLMock
。