feat(engine): 添加编辑器模式标志控制编辑器UI显示 (#274)

* feat(engine): 添加编辑器模式标志控制编辑器UI显示

- 在 Rust 引擎中添加 isEditor 标志,控制网格、gizmos、坐标轴指示器的显示
- 运行时模式下自动隐藏所有编辑器专用 UI
- 编辑器预览和浏览器运行时通过 setEditorMode(false) 禁用编辑器 UI
- 添加 Scene.isEditorMode 延迟组件生命周期回调,直到 begin() 调用
- 修复用户组件注册到 Core ComponentRegistry 以支持序列化
- 修复 Run in Browser 时用户组件加载问题

* fix: 复制引擎模块的类型定义文件到 dist/engine

* fix: 修复用户项目 tsconfig paths 类型定义路径

- 从 module.json 读取实际包名而不是使用目录名
- 修复 .d.ts 文件复制逻辑,支持 .mjs 扩展名
This commit is contained in:
YHH
2025-12-04 22:43:26 +08:00
committed by GitHub
parent 0d9bab910e
commit d7454e3ca4
16 changed files with 393 additions and 40 deletions

View File

@@ -218,6 +218,12 @@ export class GameRuntime {
Core.setScene(this._scene);
}
// 编辑器模式下设置 isEditorMode延迟组件生命周期回调
// Set isEditorMode in editor mode to defer component lifecycle callbacks
if (this._platform.isEditorMode()) {
this._scene.isEditorMode = true;
}
// 6. 添加基础系统
this._scene.addSystem(new HierarchySystem());
this._scene.addSystem(new TransformSystem());
@@ -402,6 +408,12 @@ export class GameRuntime {
this._renderSystem.setPreviewMode(true);
}
// 调用场景 begin() 触发延迟的组件生命周期回调
// Call scene begin() to trigger deferred component lifecycle callbacks
if (this._scene) {
this._scene.begin();
}
// 启用游戏逻辑系统
this._enableGameLogicSystems();
@@ -576,6 +588,31 @@ export class GameRuntime {
}
}
/**
* 设置编辑器模式
* Set editor mode
*
* When false (runtime mode), editor-only UI like grid, gizmos,
* and axis indicator are automatically hidden.
* 当为 false运行时模式编辑器专用 UI 会自动隐藏。
*/
setEditorMode(isEditor: boolean): void {
if (this._bridge) {
this._bridge.setEditorMode(isEditor);
}
}
/**
* 获取编辑器模式
* Get editor mode
*/
isEditorMode(): boolean {
if (this._bridge) {
return this._bridge.isEditorMode();
}
return true;
}
/**
* 设置清除颜色
* Set clear color