Files
cocos/tools/unity-level-prefab.md
刘宇飞 d393302388 Complete Cocos Creator port with level bundles, themes, and tooling.
Adds level prefabs, theme assets, audio, extensions, and deployment scripts for the Unity WebGL migration.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-16 15:30:58 +08:00

54 lines
1.8 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Unity 关卡 Prefab 结构说明(以 Level3 为例)
## 两套数据源
| 来源 | 文件 | 内容 |
|------|------|------|
| 逻辑配置 | `Assets/Scripts/Core/Levels600.cs` | `spawns`(玩家/道具坐标)、`boundary``levelPath` |
| 地图视觉 | `Assets/Prefabs/Level/Level3.prefab` | `Ground` / `Border` 两层 **Tilemap** |
运行时 `GameManager.CreateNewLevel`
1. Addressables 加载 `levelPath` → 实例化 `Level3` 预制体(含 Grid + Tilemap
2. 再按 `spawns` 实例化 `Player.prefab``Prop.prefab` 等到关卡根节点
**玩家/道具不在 Prefab 里**,只在 `Levels*.cs``spawns` 中定义。
## Level3.prefab 层级
```
Level3
├── Grid # cellSize (1, 0.5),等距/菱形格
├── Border # Tilemap — 墙/障碍 → GridType.Block
└── Ground # Tilemap — 可走地块 → GridType.Across / Jump
```
### 第 3 关格子(从 Prefab 解析)
- **Ground8 格)**`(-3,0)…(4,0)` 一字横排,`Baseblock` → 可走 `Across`
- **Border22 格)**:底部一排 + 左右墙 + 顶部墙,围成通道
`Levels600.cs` 中 spawns 一致:
- Player `(0,0)` North
- Prop `(-3,0)``(4,0)` 在通道两端
## Cocos 侧对应
`tools/export_unity_levels.py --prefab-dir` 会把 Prefab Tilemap 写入:
- `LevelConfig.ground`: `"x,y" → "Baseblock" | "JumpBlock"`
- `LevelConfig.border`: `"x,y" → true`
`GameManager` 按这些稀疏格子绘制地形并计算 `CalculateGridType`(与 Unity `Border.HasTile` / `Ground.GetTile` 一致)。
## 重新导出命令
```bash
python3 tools/export_unity_levels.py \
--input "/path/to/主站/Assets/Scripts/Core/Levels600.cs" \
--output assets/scripts/level/levels-20.generated.ts \
--prefab-dir "/path/to/主站/Assets/Prefabs/Level" \
--limit 20 --export-const LEVELS_20
```