BlueRoseNote/03-UnrealEngine/Gameplay/PuerTS/Puerts(一)——学习资料归纳.md

3.6 KiB
Raw Blame History

title, date, excerpt, tags, rating
title date excerpt tags rating
Puerts——学习资料归纳 2023-07-24 15:12:29 Puerts TypeScript

前言

https://github.com/Tencent/puerts

Puerts

TypeScript

TypeScript Setup

安装:

npm install -g typescript

编译:

tsc xxx.ts

Puerts

QuickStart

  1. 编译插件后进入工程,点击工具栏的ue.d.ts生成接口代码。
  2. 代码写在项目目录下的TypeScript中。(插件运行后会自动创建)
  3. 之后就会在编辑器Blueprints/TypeScript目录下出现资产图标。

调试方法

具体可以参考:# Puerts Inspector指南在UE4和Unity里调试Javascripthttps://zhuanlan.zhihu.com/p/359598262

方式1自创建虚拟机模式下调试配置

创建FJsEnv传入调试端口

//8080是调试端口 GameScript = MakeShared<puerts::FJsEnv>(std::make_unique<puerts::DefaultJSModuleLoader>(TEXT("JavaScript")), std::make_shared<puerts::FDefaultLogger>(), 8080);

阻塞等待调试器链接

GameScript = MakeShared<puerts::FJsEnv>(std::make_unique<puerts::DefaultJSModuleLoader>(TEXT("JavaScript")), std::make_shared<puerts::FDefaultLogger>(), 8080);
GameScript->WaitDebugger();
GameScript->Start("QuickStart", Arguments);

方式2自动绑定模式下调试配置

菜单上选择“编辑->项目设置”,打开设置页面后在“插件->Puerts Setting”页面中开启调试以及设置端口

TypeScript

Express

使用ts-node将ts文件编译在内存中

在使用ts-node之前需要进行全局安装

$ npm install ts-node -g

# 用ts-node直接运行项目这个库会将我们的ts文件编译成js文件保存在内存中进行引用
$ ts-node ./bin/www
# 热更新模式
$ ts-node-dev ./bin/www

虽然ts-node可以帮我们直接运行ts文件但在开发完成后部署在生产环境时还是推荐使用tsc打包出来的js文件会更加稳定。

配置npm脚本

"scripts": {
	"start": "ts-node app.ts",
	"dev": "ts-node-dev app.ts",
	"build": "tsc",
	"server": "node ./dist/app.js"
},

Puerts

热更新方法

https://zhuanlan.zhihu.com/p/364505146

UE访问Puerts

通过UDynamicDelegateProxy其成员记录了绑定的虚拟机与JS函数。