High Efficiency | 开发很快
Fast | 执行很快
因为在这套架构下,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 获得一些知识再往下进行。
build
directory. you can quickly try these 4 demo which is built by Unity2021.projects
| 打开projects
下的任意项目puerts-webgl/install
in the Menu | 点击puerts-webgl/install
PuerTS/TSLoader/Release TS to Resources
because ts-loader is used | (除了Sample1)因为使用了ts-loader,需要点击PuerTS/TSLoader/Release TS to Resources
puerts-webgl/build for browser
following the tips by step3 in console | 根据第3步出现的命令行提示,点击puerts-webgl/build for browser
将JS拷贝到构建目录
6。 append these code before </head>
in index.html built by Unity: | 将下述代码放到index.html的前
<script src="https://github.com/zombieyang/puerts_unity_webgl_demo/raw/master/puerts-runtime.js"></script>
<script src="https://github.com/zombieyang/puerts_unity_webgl_demo/raw/master/puerts_browser_js_resources.js"></script>
Install puerts first | 首先安装puerts本体 :
Install puerts-webgl | 安装PuerTS-WebGL支持:
Install puerts-webgl-jsbuild(in first time) | 安装jsbuild组件(首次运行需要):
You can also copy all the code into your Assets directory. But I don't recommend it.
Jsbuild is only for example, in most case you will need to customize it by yourself
你也可以将所有代码都复制到你的Assets目录,但我不建议这么做
Jsbuild包基本只用于示例,大部份情况下最终你都需要自己定制jsbuild代码
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
。删掉你上一次的构建产物,然后重新构建。
Player Settings > Publishing Settings > Compression Format
to Disabled
QQ群:942696334