Tencent/puerts

GitHub: Tencent/puerts

为 Unity、Unreal 和 .NET 提供高性能的多语言脚本运行时,支持 TypeScript、Lua、Python 与宿主引擎的无缝互操作。

Stars: 5963 | Forks: 817

![Logo](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/3de2482438234811.png) [![license](https://img.shields.io/badge/license-BSD_3_Clause-blue.svg)](https://github.com/Tencent/puerts/blob/master/LICENSE) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-blue.svg)](https://github.com/Tencent/puerts/pulls) ![Unity_Test](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/0633f2a3c7234819.svg) ## Unreal 发布版本 [![unreal](https://img.shields.io/badge/unreal-v1.0.9-blue.svg)](https://github.com/Tencent/puerts/releases/tag/Unreal_v1.0.9) ## Unity 发布版本 [![unity](https://img.shields.io/badge/unity-v3.0.1(latest)-blue.svg)](https://github.com/Tencent/puerts/releases/tag/Unity_v3.0.1) [![unity](https://img.shields.io/badge/unity-v2.2.3(lts)-blue.svg)](https://github.com/Tencent/puerts/releases/tag/Unity_v2.2.3) ## Nuget 发布版本 [![Puerts.V8.Complete](https://img.shields.io/nuget/v/Puerts.V8.Complete.svg?label=Puerts.V8)](https://www.nuget.org/packages/Puerts.V8.Complete) [![Puerts.NodeJS.Complete](https://img.shields.io/nuget/v/Puerts.NodeJS.Complete.svg?label=Puerts.NodeJS)](https://www.nuget.org/packages/Puerts.NodeJS.Complete) [![Puerts.QuickJS.Complete](https://img.shields.io/nuget/v/Puerts.QuickJS.Complete.svg?label=Puerts.QuickJS)](https://www.nuget.org/packages/Puerts.QuickJS.Complete) [![Puerts.Lua.Complete](https://img.shields.io/nuget/v/Puerts.Lua.Complete.svg?label=Puerts.Lua)](https://www.nuget.org/packages/Puerts.Lua.Complete) [![Puerts.Python.Complete](https://img.shields.io/nuget/v/Puerts.Python.Complete.svg?label=Puerts.Python)](https://www.nuget.org/packages/Puerts.Python.Complete) [跳转中文](#what---普洱ts是什么) ## WHAT - PuerTS 是什么? `PuerTS` 是一个用于 Unity/Unreal/DotNet 的**多语言脚本解决方案**。 * 🌐 **多语言支持(Unity 3.0 新特性!)**:JavaScript/TypeScript、**Lua** 和 **Python** —— 使用你的团队最擅长的语言,甚至可以在一个项目中混合使用。*(Unreal 目前仅支持 JavaScript/TypeScript。)* * 🚀 提供高性能的脚本运行时,并与 C#/C++ 无缝互操作。 * 📝 生成 TypeScript 声明文件,以实现对宿主引擎 API 的类型安全访问。 ## WHY - 为什么我应该使用 PuerTS? * **选择你的语言**:PuerTS 3.0 引入了统一的 `ScriptEnv` 架构 —— 使用 TypeScript、Lua 或 Python 编写游戏逻辑,并享受一致的 C# 桥接 API。不再有一刀切的方案。 * **访问海量生态**:利用 npm、LuaRocks 或 PyPI 包以及专业的游戏引擎来加速开发。 * **按需类型安全**:TypeScript 的静态类型检查显著提高了代码的健壮性,而 Lua 和 Python 则提供了快速原型的灵活性。 * **高效率**:全引擎、跨平台的反射调用 —— C++/C# 互操作零样板代码。 * **高性能**:针对性能关键路径的静态包装器生成,支持所有支持的语言。 * **卓越的 WebGL 支持**:在性能和开发效率上拥有巨大优势,某些情况下甚至比纯 C# 更快。 ## 快速开始 这三种语言共享相同的 `ScriptEnv` API —— 只需切换 `Backend`: **JavaScript / TypeScript** ``` using Puerts; using UnityEngine; void Start() { var env = new ScriptEnv(new BackendV8()); env.Eval(@" const Vector3 = CS.UnityEngine.Vector3; const Debug = CS.UnityEngine.Debug; let pos = new Vector3(1, 2, 3); Debug.Log('Hello from JS! pos = ' + pos); "); env.Dispose(); } ``` **Lua** ``` using Puerts; using UnityEngine; void Start() { var env = new ScriptEnv(new BackendLua()); env.Eval(@" local CS = require('csharp') local Vector3 = CS.UnityEngine.Vector3 local Debug = CS.UnityEngine.Debug local pos = Vector3(1, 2, 3) Debug.Log('Hello from Lua! pos = ' .. pos:ToString()) "); env.Dispose(); } ``` **Python** ``` using Puerts; using UnityEngine; void Start() { var env = new ScriptEnv(new BackendPython()); env.Eval(@" exec(''' import UnityEngine.Vector3 as Vector3 import UnityEngine.Debug as Debug pos = Vector3(1.0, 2.0, 3.0) Debug.Log('Hello from Python! pos = ' + pos.ToString()) ''') "); env.Dispose(); } ``` ## HOW - 如何开始使用 PuerTS [文档](https://puerts.github.io/en) ## 常见问题 * [通用常见问题](doc/faq.md) * [Unreal 常见问题](doc/unreal/en/faq.md) * [Unity 常见问题](doc/unity/en/faq.md) ## 如何安装 * [unreal](doc/unreal/en/install.md) * [unity](doc/unity/en/install.md) ### 更新日志 * [unreal](doc/unreal/en/changelog.md) * [unity](unity/Assets/core/upm/changelog.md) ### 已知问题 * [unreal](doc/unreal/en/bugs.md) * [unity](doc/unity/en/bugs.md) ## 选择脚本后端 PuerTS 支持多种脚本后端。对于 **JavaScript/TypeScript**,可以从 V8、QuickJS 或 Node.js 中选择。PuerTS 3.0 还新增了 **Lua** 和 **Python** 作为一等后端。 ### JavaScript 后端 * V8(默认):通常性能优异,代码体积适中,仅包含 ECMAScript 规范的实现,不包含 Node.js API 或浏览器 API。 * QuickJS:性能不如 V8,不支持调试,但代码体积小,适用于对代码体积极其敏感的场景。 * Node.js:支持 Node.js API(Unreal Engine 的移动平台上不支持 OpenSSL 相关 API),但代码体积较大。 | JS 后端 | Node API | 性能 | 代码体积 | 调试 | 备注 | | --- | --- | --- | --- | --- | --- | | V8 | ❌ | `*****` | `***` | ✔️ | | | QuickJS | ❌ | `**` | `*` | ❌ | | | Node.js | ✔️ | `*****` | `*****` | ✔️ | OpenSSL 可能被禁用 | ### 额外语言后端(Unity 3.0 新特性!) | 后端 | 语言 | 性能 | 平台支持 | 备注 | | --- | --- | --- | --- | --- | | Lua | Lua 5.4 | `*****` | 所有平台 | 适合已经在使用 Lua 的团队 | | Python | CPython | `***` | 仅桌面 | 非常适合 AI/ML 集成和工具开发 | ## 可用引擎 * unreal engine 4.22 ~ 最新版 * unity 5 ~ 最新版 * 任意 .net 项目 ## 可用平台 PuerTS 的核心代码支持游戏引擎支持的所有平台,但每个脚本后端都有自己的平台要求: | | Windows | Mac | Linux | Android | iOS | H5/小游戏 | | --- | --- | --- | --- | --- | --- | --- | | V8 | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ❌ | | Nodejs | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ❌ | | Quickjs | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | | Webgl | ❌ | ❌ | ❌ | ❌ | ❌ | ✔️ | | Lua | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | | Python | ✔️ | ✔️ | ✔️ | ❌ | ❌ | ❌ | 注 1:Unreal 仅支持 V8、Nodejs 和 Quickjs 后端。Unity 支持上面列出的所有后端。 注 2:虽然 Webgl 后端仅支持 H5/小游戏,但其脚本运行在 Web 环境的原生 JS VM 中,这通常能带来更高的性能(例如 iOS 小游戏中的 JIT 支持)。它还提供了一等语言的优点,如方便的调试和性能分析。 注 3:对于 JavaScript,不同的平台可以使用不同的 JS 后端 —— 例如移动应用使用 V8,H5 使用 Webgl —— 从而在实现全平台覆盖的同时获得最佳性能。 ## 寻求帮助 [Github Discussion](https://github.com/Tencent/puerts/discussions) ## WHAT - 普洱TS是什么? PuerTS 是 Unity/Unreal/Dotnet 下的**多语言脚本编程解决方案**。 * 🌐 **多语言支持(Unity 3.0 新特性!)**:JavaScript/TypeScript、**Lua**、**Python** 三大语言开箱即用——团队擅长什么就用什么,同一个项目里甚至可以混用。*(Unreal 目前仅支持 JavaScript/TypeScript。)* * 🚀 提供高性能脚本运行时,与 C#/C++ 无缝互操作。 * 📝 提供 TypeScript 声明文件生成能力,类型安全地访问宿主引擎 API。 ## WHY - 为什么我该用普洱TS? * **自由选择语言**:PuerTS 3.0 引入了统一的 `ScriptEnv` 架构——用 TypeScript、Lua 或 Python 编写游戏逻辑,享受一致的 C# 桥接 API,不再被某一种脚本语言绑定。 * **海量生态随手可用**:npm、LuaRocks、PyPI 的海量包 + 专业游戏引擎的渲染能力,加速开发效率。 * **按需选择类型安全**:TypeScript 的静态类型检查显著提升代码健壮性;Lua 和 Python 则提供快速原型验证的灵活性。 * **高效**:全引擎,全平台支持反射调用,无需额外步骤即可与宿主 C++/C# 通信。 * **高性能**:全引擎,全平台支持生成静态调用桥梁,所有支持的语言都兼顾了高性能场景。 * **WebGL 平台天生优势**:相比其他脚本方案,PuerTS 在 WebGL 平台性能和效率上都有极大提升,极限情况甚至比纯 C# 更快。 ## 快速上手 三种语言共享同一套 `ScriptEnv` API,只需切换 `Backend`: **JavaScript / TypeScript** ``` using Puerts; using UnityEngine; void Start() { var env = new ScriptEnv(new BackendV8()); env.Eval(@" const Vector3 = CS.UnityEngine.Vector3; const Debug = CS.UnityEngine.Debug; let pos = new Vector3(1, 2, 3); Debug.Log('Hello from JS! pos = ' + pos); "); env.Dispose(); } ``` **Lua** ``` using Puerts; using UnityEngine; void Start() { var env = new ScriptEnv(new BackendLua()); env.Eval(@" local CS = require('csharp') local Vector3 = CS.UnityEngine.Vector3 local Debug = CS.UnityEngine.Debug local pos = Vector3(1, 2, 3) Debug.Log('Hello from Lua! pos = ' .. pos:ToString()) "); env.Dispose(); } ``` **Python** ``` using Puerts; using UnityEngine; void Start() { var env = new ScriptEnv(new BackendPython()); env.Eval(@" exec(''' import UnityEngine.Vector3 as Vector3 import UnityEngine.Debug as Debug pos = Vector3(1.0, 2.0, 3.0) Debug.Log('Hello from Python! pos = ' + pos.ToString()) ''') "); env.Dispose(); } ``` ## HOW - 我该怎么开始 * [官方文档](https://puerts.github.io) ## 常见问题 * [通用 faq](doc/faq.md) * [unreal faq](doc/unreal/zhcn/faq.md) * [unity faq](doc/unity/zhcn/faq.md) ## 最新版本安装 * [unreal](doc/unreal/zhcn/install.md) * [unity](doc/unity/zhcn/install.md) ### 改动日志 * [unreal](doc/unreal/zhcn/changelog.md) * [unity](unity/Assets/core/upm/changelog-hans.md) ### 已知问题与解决办法 * [unreal](doc/unreal/zhcn/bugs.md) * [unity](doc/unity/zhcn/bugs.md) ## 脚本后端选择 PuerTS 支持多种脚本后端。**JavaScript/TypeScript** 可选 V8、QuickJS、Node.js;3.0 新增 **Lua** 和 **Python** 作为一等公民后端。 ### JavaScript 后端 * V8(默认):综合比较优秀,高性能,代码体积适中,仅包含 ECMAScript 规范的实现,不包含 Node.js API、浏览器 API。 * QuickJS:性能不如 V8,不支持调试,但代码体积小,适用于包体大小敏感的场景。 * Node.js:支持 Node.js API(Unreal Engine 移动平台下不支持 OpenSSL 相关 API),代码体积较大。 | JS 后端 | Node API | 性能 | 代码体积 | 调试 | 补充 | | --- | --- | --- | --- | --- | --- | | V8 | ❌ | `*****` | `***` | ✔️ | | | QuickJS | ❌ | `**` | `*` | ❌ | | | Node.js | ✔️ | `*****` | `*****` | ✔️ | OpenSSL 可能被禁用 | ### 新增语言后端(Unity 3.0 新特性!) | 后端 | 语言 | 性能 | 平台支持 | 补充 | | --- | --- | --- | --- | --- | | Lua | Lua 5.4 | `*****` | 全平台 | 适合已有 Lua 技术栈的团队 | | Python | CPython | `***` | 桌面平台 | 适合 AI/ML 集成与工具链开发 | ## 可用引擎 * unreal engine 4.22 ~ latest * unity 5 ~ latest * 任意.net环境 ## 可用平台 PuerTS的核心代码支持游戏引擎支持的所有平台,但每个脚本后端有其特有的平台要求: | | Window | Mac | Linux | Android | IOS | H5/小游戏| | --- | --- | --- | --- | --- | --- |--- | | V8 | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ❌ | | Nodejs | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ❌ | | Quickjs | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | | Webgl | ❌ | ❌ | ❌ | ❌ | ❌ | ✔️ | | Lua | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | | Python | ✔️ | ✔️ | ✔️ | ❌ | ❌ | ❌ | 注1: Unreal下只有V8、Nodejs、Quickjs三种后端,Unity支持以上所有脚本后端 注2: Webgl后端虽然只支持H5/小游戏,但它的脚本是运行在web环境的原生js虚拟机里,通常性能更高(比如在ios小游戏环境里支持jit),也能享受first class语言诸如方便调试,profiler等好处 注3: 对于js,不同平台可以选不同的js脚本后端,比如app选v8,H5平台选Webgl实现全平台支持且性能最优 ## 技术支持 [Github Discussion](https://github.com/Tencent/puerts/discussions) QQ群:942696334 UE4专属群:689643903 ## 开发博客 [知乎专栏](https://www.zhihu.com/column/c_1355534112468402176)
标签:CMS安全, DotNet, JavaScript, Lua, MITM代理, NuGet, Puerts, Python, QuickJS, rizin, TypeScript, Unity, Unreal Engine, V8, 多人体追踪, 多语言支持, 安全插件, 安全测试框架, 插件, 数据可视化, 无后门, 普洱, 游戏开发, 游戏引擎, 热更新, 编程框架, 脚本绑定, 脚本解决方案, 脚本语言, 腾讯开源, 逆向工具