uts2puerts

1.0.16 • Public • Published

uts2puerts

内部工具

介绍

将使用uts引擎的工程转译为使用puerts引擎工程的代码。

使用uts的TypeScript代码和使用puerts的略有不同,比如:

  • puerts需要import CSharp from 'csharp',uts不需要
  • uts: UnityEngine.GameObject VS. puerts: CSharp.UnityEngine.GameObject
  • uts: uts.log(...) VS. puerts: console.log(...)
  • uts可直接传数组给CS,puerts需构造诸如CSharp.System.Array$1<T>类型的对象
  • uts的事件全部转换成委托,puerts支持AddListener
  • etc.

本工具用于编译时自动转译代码,从而生成puerts版本项目。

安装教程

npm i uts2puerts -g

使用说明

uts2puerts -p projectRoot -r translateRule.txt
  1. -p/--project-root: 指定工程路径
  2. -r/--rule: 指定转译规则配置

转译规则配置

大部分转译可自动完成,部分无法自动完成的,可提供配置进行逐一替换,规则文件格式如下:

TsScripts\System\login\LoginModule.ts
import { ArrayUtil } from "System/utils/ArrayUtil";
>>>>>>>>>>>>
let request = CSharp.ResLoader.CreateAssetsRequest(CSharp.AssetPriority.High1, [UIPathData.CreateRoleView]);
<<<<<<<<<<<<
let request = CSharp.ResLoader.CreateAssetsRequest(CSharp.AssetPriority.High1, ArrayUtil.toStringArray([UIPathData.CreateRoleView]));
------------
TsScripts\System\test\TestView.ts
>>>>>>>>>>>>
textline.onValueChanged = delegate(this, this.onInputChange, this.m_dcnt);
<<<<<<<<<<<<
(textline.onValueChanged as unknown as CSharp.UnityEngine.Events.UnityEvent).AddListener((value?: string)=>this.onInputChange(value, this.m_dcnt));

多个文件使用------------分割 每个文件替换规则分如下几部分:

  • 文件相对路径和需要添加的import语句(如果有)
  • 原始待替换语句,以>>>>>>>>>>>>开始
  • 替换后语句,以<<<<<<<<<<<<开始

Readme

Keywords

Package Sidebar

Install

npm i uts2puerts

Weekly Downloads

3

Version

1.0.16

License

Apache-2.0

Unpacked Size

27.3 kB

Total Files

8

Last publish

Collaborators

  • taiyosen