fix(prefab): 修复预制体编辑模式的保存与退出,使用原生 scene://edit-mode 接口替代无效的 IPC 广播,更新相关使用文档与安全规定

This commit is contained in:
火焰库拉
2026-03-08 11:33:28 +08:00
parent fb4025e50b
commit 2573c0f478
15 changed files with 443 additions and 13 deletions

View File

@@ -20,6 +20,16 @@
5. 所有节点和组件的 `_id` 字段必须为空字符串(运行时由引擎分配)。
6. 文件中不能包含 `cc.Scene` 对象。
### 1.3 预制体界面的打开与保存
- **推荐工具**:使用 `open_prefab` `save_prefab`,和 `close_prefab` 工具。
- **痛点**:直觉上 AI 可能会推断应该通过 `scene:save-prefab``scene:close-prefab` 这样的 IPC 指令来实现“保存”与“退出预制体视图”,但实际上这类消息在引擎内部并不存在。
- **正规实现(封装在工具内)**
必须在负责渲染场景面板的渲染进程Scene Process直接 `require("scene://edit-mode")`,然后对当前的状态机进行控制。
- 保存:`require("scene://edit-mode").save()`
- 退出:`require("scene://edit-mode").pop()`
这彻底解决了进入预制体模式后出不去或者没法存盘的痛点。AI 在使用 `save_prefab``close_prefab` 工具时就是在触发这两行代码。
---
## 2. 脚本属性Inspector关联