unity-puerts-template/readme.md

34 lines
806 B
Markdown
Raw Normal View History

2025-03-30 12:27:26 +08:00
# Unity Puerts 模板
2025-03-30 12:36:13 +08:00
## 工作方式
2025-03-30 12:27:26 +08:00
2025-03-30 12:36:13 +08:00
- 正常npm项目输出一个js bundle与unity独立
- 依赖Unity生成的类型绑定将打包放入同一目录的Resources文件夹内
2025-03-30 12:27:26 +08:00
2025-03-30 12:36:13 +08:00
## 安装配置
2025-03-30 12:27:26 +08:00
2025-03-30 12:36:13 +08:00
- clone本仓库到unity项目外任意路径npm install安装依赖
- 将Unity项目的`Assets/Gen` symlink到根目录下
- 配置`.gitignore`,忽略`Assets/Gen`文件夹内容
## 类型检查
- 虽然puerts生成的`CS.namespace.xxx`即使不作额外配置也能用,但没有自动补全
- 为了使用自动补全,需要额外添加类型标注
- 在`modules.d.ts`中添加:
```typescript
declare module "包名" {
export = CS.包名;
}
```
- 在`rspack.config.ts`中添加额外的`externals`:
```typescript
externals: {
"包名": "CS.包名"
}
```