refactor(editor): 统一配置管理、完善插件卸载和热更新同步 (#298)
主要变更: 1. 统一配置管理 (EditorConfig) - 新增 EditorConfig 集中管理路径、文件名、全局变量等配置 - 添加 SDK 模块配置系统 (ISDKModuleConfig) - 重构 PluginSDKRegistry 使用配置而非硬编码 2. 完善插件卸载机制 - 扩展 PluginRegisteredResources 追踪运行时资源 - 实现完整的 deactivatePluginRuntime 清理流程 - ComponentRegistry 添加 unregister/getRegisteredComponents 方法 3. 热更新同步机制 - 新增 HotReloadCoordinator 协调热更新过程 - 热更新期间暂停 ECS 循环避免竞态条件 - 支持超时保护和失败恢复
This commit is contained in:
@@ -36,6 +36,9 @@ export abstract class Component implements IComponent {
|
||||
* 组件ID生成器
|
||||
*
|
||||
* 用于为每个组件分配唯一的ID。
|
||||
*
|
||||
* Component ID generator.
|
||||
* Used to assign unique IDs to each component.
|
||||
*/
|
||||
private static idGenerator: number = 0;
|
||||
|
||||
|
||||
@@ -259,8 +259,64 @@ export class ComponentRegistry {
|
||||
return this.hotReloadEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* 注销组件类型
|
||||
* Unregister component type
|
||||
*
|
||||
* 用于插件卸载时清理组件。
|
||||
* 注意:这不会释放 bitIndex,以避免索引冲突。
|
||||
*
|
||||
* Used for cleanup during plugin unload.
|
||||
* Note: This does not release bitIndex to avoid index conflicts.
|
||||
*
|
||||
* @param componentName 组件名称 | Component name
|
||||
*/
|
||||
public static unregister(componentName: string): void {
|
||||
const componentType = this.componentNameToType.get(componentName);
|
||||
if (!componentType) {
|
||||
return;
|
||||
}
|
||||
|
||||
const bitIndex = this.componentTypes.get(componentType);
|
||||
|
||||
// 移除类型映射
|
||||
// Remove type mappings
|
||||
this.componentTypes.delete(componentType);
|
||||
if (bitIndex !== undefined) {
|
||||
this.bitIndexToType.delete(bitIndex);
|
||||
}
|
||||
this.componentNameToType.delete(componentName);
|
||||
this.componentNameToId.delete(componentName);
|
||||
|
||||
// 清除相关的掩码缓存
|
||||
// Clear related mask cache
|
||||
this.clearMaskCache();
|
||||
|
||||
this._logger.debug(`Component unregistered: ${componentName}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有已注册的组件信息
|
||||
* Get all registered component info
|
||||
*
|
||||
* @returns 组件信息数组 | Array of component info
|
||||
*/
|
||||
public static getRegisteredComponents(): Array<{ name: string; type: Function; bitIndex: number }> {
|
||||
const result: Array<{ name: string; type: Function; bitIndex: number }> = [];
|
||||
|
||||
for (const [name, type] of this.componentNameToType) {
|
||||
const bitIndex = this.componentTypes.get(type);
|
||||
if (bitIndex !== undefined) {
|
||||
result.push({ name, type, bitIndex });
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置注册表(用于测试)
|
||||
* Reset registry (for testing)
|
||||
*/
|
||||
public static reset(): void {
|
||||
this.componentTypes.clear();
|
||||
|
||||
Reference in New Issue
Block a user