From 01293590e8fa36cd469a6f0756a78ffe706cdb10 Mon Sep 17 00:00:00 2001 From: yhh <359807859@qq.com> Date: Tue, 16 Dec 2025 11:23:50 +0800 Subject: [PATCH] =?UTF-8?q?feat(editor-core):=20=E6=94=B9=E8=BF=9B?= =?UTF-8?q?=E7=BC=96=E8=BE=91=E5=99=A8=E6=A0=B8=E5=BF=83=E6=9C=8D=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - EntityStoreService 添加调试日志 - AssetRegistryService 优化资产注册 - PluginManager 改进插件管理 - IFileAPI 添加 getFileMtime 接口 --- .../editor-core/src/Plugin/PluginManager.ts | 12 +++++------ .../src/Services/AssetRegistryService.ts | 20 +++++++++++++++---- .../src/Services/EntityStoreService.ts | 5 ++++- packages/editor-core/src/Types/IFileAPI.ts | 9 +++++++++ 4 files changed, 35 insertions(+), 11 deletions(-) diff --git a/packages/editor-core/src/Plugin/PluginManager.ts b/packages/editor-core/src/Plugin/PluginManager.ts index 1ceaf520..0e64d85a 100644 --- a/packages/editor-core/src/Plugin/PluginManager.ts +++ b/packages/editor-core/src/Plugin/PluginManager.ts @@ -3,7 +3,7 @@ * Unified Plugin Manager */ -import { createLogger, ComponentRegistry } from '@esengine/ecs-framework'; +import { createLogger, GlobalComponentRegistry } from '@esengine/ecs-framework'; import type { IScene, ServiceContainer, IService } from '@esengine/ecs-framework'; import type { ModuleManifest, @@ -670,9 +670,9 @@ export class PluginManager implements IService { // 注册组件(使用包装的 Registry 来跟踪) // Register components (use wrapped registry to track) if (runtimeModule.registerComponents) { - const componentsBefore = new Set(ComponentRegistry.getRegisteredComponents().map(c => c.name)); - runtimeModule.registerComponents(ComponentRegistry); - const componentsAfter = ComponentRegistry.getRegisteredComponents(); + const componentsBefore = new Set(GlobalComponentRegistry.getRegisteredComponents().map(c => c.name)); + runtimeModule.registerComponents(GlobalComponentRegistry); + const componentsAfter = GlobalComponentRegistry.getRegisteredComponents(); // 跟踪新注册的组件 // Track newly registered components @@ -779,7 +779,7 @@ export class PluginManager implements IService { if (resources.componentTypeNames.length > 0) { for (const componentName of resources.componentTypeNames) { try { - ComponentRegistry.unregister(componentName); + GlobalComponentRegistry.unregister(componentName); logger.debug(`Component unregistered: ${componentName}`); } catch (e) { logger.error(`Failed to unregister component ${componentName}:`, e); @@ -900,7 +900,7 @@ export class PluginManager implements IService { const runtimeModule = plugin.plugin.runtimeModule; if (runtimeModule?.registerComponents) { try { - runtimeModule.registerComponents(ComponentRegistry); + runtimeModule.registerComponents(GlobalComponentRegistry); logger.debug(`Components registered for: ${pluginId}`); } catch (e) { logger.error(`Failed to register components for ${pluginId}:`, e); diff --git a/packages/editor-core/src/Services/AssetRegistryService.ts b/packages/editor-core/src/Services/AssetRegistryService.ts index e2a08e09..9af15f76 100644 --- a/packages/editor-core/src/Services/AssetRegistryService.ts +++ b/packages/editor-core/src/Services/AssetRegistryService.ts @@ -394,8 +394,14 @@ export class AssetRegistryService implements IService { // 处理文件创建 - 注册新资产并生成 .meta if (changeType === 'create' || changeType === 'modify') { for (const absolutePath of paths) { - // Skip .meta files - if (absolutePath.endsWith('.meta')) continue; + // Handle .meta file changes - invalidate cache + // 处理 .meta 文件变化 - 使缓存失效 + if (absolutePath.endsWith('.meta')) { + const assetPath = absolutePath.slice(0, -5); // Remove '.meta' suffix + this._metaManager.invalidateCache(assetPath); + logger.debug(`Meta file changed, invalidated cache for: ${assetPath}`); + continue; + } // Only process files in managed directories // 只处理托管目录中的文件 @@ -406,8 +412,14 @@ export class AssetRegistryService implements IService { } } else if (changeType === 'remove') { for (const absolutePath of paths) { - // Skip .meta files - if (absolutePath.endsWith('.meta')) continue; + // Handle .meta file deletion - invalidate cache + // 处理 .meta 文件删除 - 使缓存失效 + if (absolutePath.endsWith('.meta')) { + const assetPath = absolutePath.slice(0, -5); + this._metaManager.invalidateCache(assetPath); + logger.debug(`Meta file removed, invalidated cache for: ${assetPath}`); + continue; + } // Only process files in managed directories // 只处理托管目录中的文件 diff --git a/packages/editor-core/src/Services/EntityStoreService.ts b/packages/editor-core/src/Services/EntityStoreService.ts index dd1306b4..6cae6da4 100644 --- a/packages/editor-core/src/Services/EntityStoreService.ts +++ b/packages/editor-core/src/Services/EntityStoreService.ts @@ -95,6 +95,9 @@ export class EntityStoreService implements IService { this.entities.clear(); this.rootEntityIds = []; + // 调试:打印场景实体信息 | Debug: print scene entity info + logger.info(`[syncFromScene] Scene name: ${scene.name}, entities.count: ${scene.entities.count}`); + let entityCount = 0; scene.entities.forEach((entity) => { entityCount++; @@ -106,7 +109,7 @@ export class EntityStoreService implements IService { } }); - logger.debug(`syncFromScene: synced ${entityCount} entities, ${this.rootEntityIds.length} root entities`); + logger.info(`[syncFromScene] Synced ${entityCount} entities, ${this.rootEntityIds.length} root entities`); if (this.rootEntityIds.length > 0) { const rootNames = this.rootEntityIds .map(id => this.entities.get(id)?.name) diff --git a/packages/editor-core/src/Types/IFileAPI.ts b/packages/editor-core/src/Types/IFileAPI.ts index 109a4fa3..137d5d93 100644 --- a/packages/editor-core/src/Types/IFileAPI.ts +++ b/packages/editor-core/src/Types/IFileAPI.ts @@ -61,4 +61,13 @@ export interface IFileAPI { * @returns 路径是否存在 */ pathExists(path: string): Promise; + + /** + * 获取文件修改时间 + * Get file modification time + * + * @param path 文件路径 | File path + * @returns 文件修改时间(毫秒时间戳)| File modification time (milliseconds timestamp) + */ + getFileMtime?(path: string): Promise; }