本项目包括了一个可以以WebGL模式构建运行Puerts的Unity项目。puerts的JS代码会运行在浏览器JS引擎里,而不是运行在编译为WASM的JS解释器里。
You can build a unity puerts project in webgl mode now. Your Javascript code will run in browser Javascript engine instead of a interpreter in WASM.
- unity 2019支持 ✔
- unity 2020支持 ×
- 简单旋转demo
Assets/Scenes/SampleScene
✔ - 篮球小游戏demo
Assets/Scenes/BasketballDemo
✔
因为大量使用到了WeakRef
和FinalizationRegistry
API。该功能在以下环境下可用:
This feature will deeply depend the
WeakRef
andFinalizationRegistry
API. Which are supported in below environment:
- V8 8.4+ (eg. Chrome 84+)
- iOS Safari 14.5+/OSX Safari 14.1+
- 运作原理(how this work?)
Puerts的WebGL版本是利用Unity官方提供的Unity代码与浏览器脚本交互的功能,对Puerts中使用到的PuertsDLL.cs
里的API通过JS一一进行实现。关键代码位于Assets/Plugins/puerts.jslib
。
With this Manual which provided by Unity. We implements a jslib located at
Assets/Plugins/puerts.jslib
. It should provide the API inPuertsDLL.cs
which support Puerts to run.
- 未来还有以下工作要做(TODO):
- 在jslib实现剩余的PuertsDLL.cs的API
- 支持2020 2021