feat: 预制体系统与架构改进 (#303)
* feat(prefab): 实现预制体系统和编辑器 UX 改进 ## 预制体系统 - 新增 PrefabSerializer: 预制体序列化/反序列化 - 新增 PrefabInstanceComponent: 追踪预制体实例来源和修改 - 新增 PrefabService: 预制体核心服务 - 新增 PrefabLoader: 预制体资产加载器 - 新增预制体命令: Create/Instantiate/Apply/Revert/BreakLink ## 预制体编辑模式 - 支持双击 .prefab 文件进入编辑模式 - 预制体编辑模式工具栏 (保存/退出) - 预制体实例指示器和操作菜单 ## 编辑器 UX 改进 - SceneHierarchy 快捷键: F2 重命名, Ctrl+D 复制, ↑↓ 导航 - 支持双击实体名称内联编辑 - 删除实体时显示子节点数量警告 - 右键菜单添加重命名/复制选项及快捷键提示 - 布局持久化和重置功能 ## Bug 修复 - 修复 editor-runtime 组件类重复导致的 TransformComponent 不识别问题 - 修复 .prefab-name 样式覆盖导致预制体工具栏文字不可见 - 修复 Inspector 资源字段高度不正确问题 * feat(editor): 改进编辑器 UX 交互体验 - ContentBrowser: 加载动画 spinner、搜索高亮、改进空状态设计 - SceneHierarchy: 选中项自动滚动到视图、搜索清除按钮 - PropertyInspector: 输入框本地状态管理、Enter/Escape 键处理 - EntityInspector: 组件折叠状态持久化、属性搜索清除按钮 - Viewport: 变换操作实时数值显示 - 国际化: 添加相关文本 (en/zh) * fix(build): 修复 Web 构建资产加载和编辑器 UX 改进 构建系统修复: - 修复 asset-catalog.json 字段名不匹配 (entries vs assets) - 修复 BrowserFileSystemService 支持两种目录格式 - 修复 bundle 策略检测逻辑 (空对象判断) - 修复 module.json 中 assetExtensions 声明和类型推断 行为树修复: - 修复 BehaviorTreeExecutionSystem 使用 loadAsset 替代 loadAssetByPath - 修复 BehaviorTreeAssetType 常量与 module.json 类型名一致 (behavior-tree) 编辑器 UX 改进: - 构建完成对话框添加"打开文件夹"按钮 - 构建完成对话框样式优化 (圆形图标背景、按钮布局) - SceneHierarchy 响应式布局 (窄窗口自动隐藏 Type 列) - SceneHierarchy 隐藏滚动条 错误追踪: - 添加全局错误处理器写入日志文件 (%TEMP%/esengine-editor-crash.log) - 添加 append_to_log Tauri 命令 * feat(render): 修复 UI 渲染和点击特效系统 ## UI 渲染修复 - 修复 GUID 验证 bug,使用统一的 isValidGUID() 函数 - 修复 UI 渲染顺序随机问题,Rust 端使用 IndexMap 替代 HashMap - Web 运行时添加 assetPathResolver 支持 GUID 解析 - UIInteractableComponent.blockEvents 默认值改为 false ## 点击特效系统 - 新增 ClickFxComponent 和 ClickFxSystem - 支持在点击位置播放粒子效果 - 支持多种触发模式和粒子轮换 ## Camera 系统重构 - CameraSystem 从 ecs-engine-bindgen 移至 camera 包 - 新增 CameraManager 统一管理相机 ## 编辑器改进 - 改进属性面板 UI 交互 - 粒子编辑器面板优化 - Transform 命令系统 * feat(render): 实现 Sorting Layer 系统和 Overlay 渲染层 - 新增 SortingLayerManager 管理排序层级 (Background, Default, Foreground, UI, Overlay) - 实现 ISortable 接口,统一 Sprite、UI、Particle 的排序属性 - 修复粒子 Overlay 层被 UI 遮挡问题:添加独立的 Overlay Pass 在 UI 之后渲染 - 更新粒子资产格式:从 sortingOrder 改为 sortingLayer + orderInLayer - 更新粒子编辑器面板支持新的排序属性 - 优化 UI 渲染系统使用新的排序层级 * feat(ci): 集成 SignPath 代码签名服务 - 添加 SignPath 自动签名工作流(Windows) - 配置 release-editor.yml 支持代码签名 - 将构建改为草稿模式,等待签名完成后发布 - 添加证书文件到 .gitignore 防止泄露 * fix(asset): 修复 Web 构建资产路径解析和全局单例移除 ## 资产路径修复 - 修复 Tauri 本地服务器 `/asset?path=...` 路径解析,正确与 root 目录连接 - BrowserPathResolver 支持两种模式: - 'proxy': 使用 /asset?path=... 格式(编辑器 Run in Browser) - 'direct': 使用直接路径 /assets/path.png(独立 Web 构建) - BrowserRuntime 使用 'direct' 模式,无需 Tauri 代理 ## 架构改进 - 移除全局单例 - 移除 globalAssetManager 导出,改用 AssetManagerToken 依赖注入 - 移除 globalPathResolver 导出,改用 PathResolutionService - 移除 globalPathResolutionService 导出 - ParticleUpdateSystem/ClickFxSystem 通过 setAssetManager() 注入依赖 - EngineService 使用 new AssetManager() 替代全局实例 ## 新增服务 - PathResolutionService: 统一路径解析接口 - RuntimeModeService: 运行时模式查询服务 - SerializationContext: EntityRef 序列化上下文 ## 其他改进 - 完善 ServiceToken 注释说明本地定义的意图 - 导出 BrowserPathResolveMode 类型 * fix(build): 添加 world-streaming composite 设置修复类型检查 * fix(build): 移除 world-streaming 引用避免 composite 冲突 * fix(build): 将 const enum 改为 enum 兼容 isolatedModules * fix(build): 添加缺失的 IAssetManager 导入
This commit is contained in:
@@ -6,11 +6,10 @@
|
||||
* This is the unified entry point for editor preview and standalone runtime
|
||||
*/
|
||||
|
||||
import { Core, Scene, SceneSerializer, HierarchySystem } from '@esengine/ecs-framework';
|
||||
import { Core, Scene, SceneSerializer, HierarchySystem, PluginServiceRegistry, createServiceToken } from '@esengine/ecs-framework';
|
||||
import {
|
||||
EngineBridge,
|
||||
EngineRenderSystem,
|
||||
CameraSystem,
|
||||
EngineBridgeToken,
|
||||
RenderSystemToken,
|
||||
EngineIntegrationToken,
|
||||
@@ -21,15 +20,25 @@ import {
|
||||
TransformSystem,
|
||||
InputSystem,
|
||||
Input,
|
||||
PluginServiceRegistry,
|
||||
TransformTypeToken,
|
||||
createServiceToken
|
||||
CanvasElementToken
|
||||
} from '@esengine/engine-core';
|
||||
import { AssetManager, EngineIntegration, AssetManagerToken } from '@esengine/asset-system';
|
||||
|
||||
// ============================================================================
|
||||
// 本地服务令牌定义 | Local Service Token Definitions
|
||||
// 用于访问各模块注册的服务 | For accessing services registered by modules
|
||||
// ============================================================================
|
||||
// 这些令牌使用 createServiceToken() 本地定义,而不是从源模块导入。
|
||||
// 这是有意为之:
|
||||
// 1. runtime-core 应保持与 ui/sprite/behavior-tree 等模块的松耦合
|
||||
// 2. createServiceToken() 使用 Symbol.for(),确保相同名称在运行时匹配
|
||||
// 3. 本地接口提供类型安全,无需引入模块依赖
|
||||
//
|
||||
// These tokens are defined locally using createServiceToken() instead of
|
||||
// importing from source modules. This is intentional:
|
||||
// 1. runtime-core should remain loosely coupled to ui/sprite/behavior-tree etc.
|
||||
// 2. createServiceToken() uses Symbol.for(), ensuring same names match at runtime
|
||||
// 3. Local interfaces provide type safety without introducing module dependencies
|
||||
// ============================================================================
|
||||
|
||||
/**
|
||||
@@ -88,6 +97,7 @@ const Physics2DSystemToken = createServiceToken<IPhysicsSystem>('physics2DSystem
|
||||
|
||||
// Tilemap 模块服务令牌 | Tilemap module service tokens
|
||||
const TilemapSystemToken = createServiceToken<ITilemapSystem>('tilemapSystem');
|
||||
|
||||
import {
|
||||
runtimePluginManager,
|
||||
type SystemContext,
|
||||
@@ -154,7 +164,6 @@ export class GameRuntime {
|
||||
private _bridge: EngineBridge | null = null;
|
||||
private _scene: Scene | null = null;
|
||||
private _renderSystem: EngineRenderSystem | null = null;
|
||||
private _cameraSystem: CameraSystem | null = null;
|
||||
private _inputSystem: InputSystem | null = null;
|
||||
private _assetManager: AssetManager | null = null;
|
||||
private _engineIntegration: EngineIntegration | null = null;
|
||||
@@ -174,7 +183,8 @@ export class GameRuntime {
|
||||
private _systemContext: SystemContext | null = null;
|
||||
|
||||
// 场景快照(用于编辑器预览后恢复)
|
||||
private _sceneSnapshot: string | null = null;
|
||||
// 支持二进制格式以提升性能
|
||||
private _sceneSnapshot: string | Uint8Array | null = null;
|
||||
|
||||
// Gizmo 注册表注入函数
|
||||
private _gizmoDataProvider?: (component: any, entity: any, isSelected: boolean) => any;
|
||||
@@ -318,8 +328,8 @@ export class GameRuntime {
|
||||
this._inputSystem.setInputSubsystem(inputSubsystem);
|
||||
}
|
||||
|
||||
this._cameraSystem = new CameraSystem(this._bridge);
|
||||
this._scene.addSystem(this._cameraSystem);
|
||||
// CameraSystem 由 CameraPlugin 通过插件系统创建
|
||||
// CameraSystem is created by CameraPlugin via plugin system
|
||||
|
||||
this._renderSystem = new EngineRenderSystem(this._bridge, TransformComponent);
|
||||
|
||||
@@ -352,6 +362,13 @@ export class GameRuntime {
|
||||
services.register(AssetManagerToken, this._assetManager);
|
||||
services.register(TransformTypeToken, TransformComponent);
|
||||
|
||||
// 注册 Canvas 元素(用于坐标转换等)
|
||||
// Register canvas element (for coordinate conversion, etc.)
|
||||
const canvas = this._platform.getCanvas();
|
||||
if (canvas) {
|
||||
services.register(CanvasElementToken, canvas);
|
||||
}
|
||||
|
||||
this._systemContext = {
|
||||
isEditor: this._platform.isEditorMode(),
|
||||
services
|
||||
@@ -516,6 +533,12 @@ export class GameRuntime {
|
||||
this._renderSystem.setPreviewMode(true);
|
||||
}
|
||||
|
||||
// 禁用编辑器模式,启用 InputSystem 和组件生命周期回调
|
||||
// Disable editor mode to enable InputSystem and component lifecycle callbacks
|
||||
if (this._scene) {
|
||||
this._scene.isEditorMode = false;
|
||||
}
|
||||
|
||||
// 调用场景 begin() 触发延迟的组件生命周期回调
|
||||
// Call scene begin() to trigger deferred component lifecycle callbacks
|
||||
if (this._scene) {
|
||||
@@ -577,6 +600,12 @@ export class GameRuntime {
|
||||
this._renderSystem.setPreviewMode(false);
|
||||
}
|
||||
|
||||
// 恢复编辑器模式(如果是编辑器平台)
|
||||
// Restore editor mode (if editor platform)
|
||||
if (this._scene && this._platform.isEditorMode()) {
|
||||
this._scene.isEditorMode = true;
|
||||
}
|
||||
|
||||
// 解绑 UI 输入
|
||||
const services = this._systemContext?.services;
|
||||
const uiInputSystem = services?.get(UIInputSystemToken);
|
||||
@@ -848,19 +877,41 @@ export class GameRuntime {
|
||||
/**
|
||||
* 保存场景快照
|
||||
* Save scene snapshot
|
||||
*
|
||||
* 使用二进制格式提升序列化性能,并支持 EntityRef 的正确序列化。
|
||||
* 在保存前清除纹理缓存,确保恢复时能够从干净状态重新加载纹理。
|
||||
*
|
||||
* Uses binary format for better serialization performance and supports proper
|
||||
* EntityRef serialization. Clears texture cache before saving to ensure
|
||||
* clean reload on restore.
|
||||
*
|
||||
* @param options 可选配置
|
||||
* @param options.useJson 是否使用 JSON 格式(用于调试),默认 false 使用二进制
|
||||
*/
|
||||
saveSceneSnapshot(): boolean {
|
||||
saveSceneSnapshot(options?: { useJson?: boolean }): boolean {
|
||||
if (!this._scene) {
|
||||
console.warn('[GameRuntime] Cannot save snapshot: no scene');
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
// 清除所有纹理缓存(确保恢复时重新加载)
|
||||
// Clear all texture caches (ensures reload on restore)
|
||||
// clearTextureMappings() 内部会同时清除 Rust 层和 JS 层的纹理缓存
|
||||
// clearTextureMappings() internally clears both Rust and JS layer texture caches
|
||||
if (this._engineIntegration) {
|
||||
this._engineIntegration.clearTextureMappings();
|
||||
}
|
||||
|
||||
// 使用二进制格式提升性能(默认)或 JSON 用于调试
|
||||
// Use binary format for performance (default) or JSON for debugging
|
||||
const format = options?.useJson ? 'json' : 'binary';
|
||||
|
||||
this._sceneSnapshot = SceneSerializer.serialize(this._scene, {
|
||||
format: 'json',
|
||||
format,
|
||||
pretty: false,
|
||||
includeMetadata: false
|
||||
}) as string;
|
||||
});
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error('[GameRuntime] Failed to save snapshot:', error);
|
||||
@@ -871,6 +922,14 @@ export class GameRuntime {
|
||||
/**
|
||||
* 恢复场景快照
|
||||
* Restore scene snapshot
|
||||
*
|
||||
* 使用两阶段反序列化确保 EntityRef 引用正确恢复:
|
||||
* 1. 创建所有实体和组件
|
||||
* 2. 解析所有 EntityRef 引用
|
||||
*
|
||||
* Uses two-phase deserialization to ensure EntityRef references are properly restored:
|
||||
* 1. Create all entities and components
|
||||
* 2. Resolve all EntityRef references
|
||||
*/
|
||||
async restoreSceneSnapshot(): Promise<boolean> {
|
||||
if (!this._scene || !this._sceneSnapshot) {
|
||||
@@ -885,7 +944,16 @@ export class GameRuntime {
|
||||
tilemapSystem.clearCache?.();
|
||||
}
|
||||
|
||||
// 反序列化场景
|
||||
// 清除所有纹理并重置状态(修复 Play/Stop 后纹理 ID 混乱的问题)
|
||||
// Clear all textures and reset state (fixes texture ID confusion after Play/Stop)
|
||||
// clearTextureMappings() 内部会同时清除 Rust 层和 JS 层的纹理缓存
|
||||
// clearTextureMappings() internally clears both Rust and JS layer texture caches
|
||||
if (this._engineIntegration) {
|
||||
this._engineIntegration.clearTextureMappings();
|
||||
}
|
||||
|
||||
// 反序列化场景(SceneSerializer 内部使用 SerializationContext 处理 EntityRef)
|
||||
// Deserialize scene (SceneSerializer internally uses SerializationContext for EntityRef)
|
||||
SceneSerializer.deserialize(this._scene, this._sceneSnapshot, {
|
||||
strategy: 'replace',
|
||||
preserveIds: true
|
||||
@@ -907,6 +975,20 @@ export class GameRuntime {
|
||||
return this._sceneSnapshot !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取快照大小(用于调试)
|
||||
* Get snapshot size (for debugging)
|
||||
*/
|
||||
getSnapshotSize(): number {
|
||||
if (!this._sceneSnapshot) {
|
||||
return 0;
|
||||
}
|
||||
if (typeof this._sceneSnapshot === 'string') {
|
||||
return this._sceneSnapshot.length;
|
||||
}
|
||||
return this._sceneSnapshot.byteLength;
|
||||
}
|
||||
|
||||
// ===== 多视口 API =====
|
||||
// ===== Multi-viewport API =====
|
||||
|
||||
@@ -963,7 +1045,6 @@ export class GameRuntime {
|
||||
}
|
||||
|
||||
this._renderSystem = null;
|
||||
this._cameraSystem = null;
|
||||
this._inputSystem = null;
|
||||
this._systemContext = null;
|
||||
this._platform.dispose();
|
||||
|
||||
Reference in New Issue
Block a user