()
| 437 | |
| 438 | useEffect(() => { |
| 439 | const initializeEditor = async () => { |
| 440 | // 使用 ref 防止 React StrictMode 的双重调用 |
| 441 | if (initRef.current) { |
| 442 | return; |
| 443 | } |
| 444 | initRef.current = true; |
| 445 | |
| 446 | try { |
| 447 | // ECS Framework 已通过 PluginSDKRegistry 暴露到全局 |
| 448 | // ECS Framework is exposed globally via PluginSDKRegistry |
| 449 | |
| 450 | const editorScene = new Scene(); |
| 451 | Core.setScene(editorScene); |
| 452 | |
| 453 | const serviceRegistry = new ServiceRegistry(); |
| 454 | const services = serviceRegistry.registerAllServices(coreInstance); |
| 455 | |
| 456 | serviceRegistry.setupRemoteLogListener(services.logService); |
| 457 | |
| 458 | const pluginInstaller = new PluginInstaller(); |
| 459 | await pluginInstaller.installBuiltinPlugins(services.pluginManager); |
| 460 | |
| 461 | // 初始化编辑器模块(安装设置、面板等) |
| 462 | await services.pluginManager.initializeEditor(Core.services); |
| 463 | |
| 464 | services.notification.setCallbacks(showToast, hideToast); |
| 465 | (services.dialog as IDialogExtended).setConfirmCallback(setConfirmDialog); |
| 466 | |
| 467 | services.messageHub.subscribe('ui:openWindow', (data: any) => { |
| 468 | const { windowId } = data; |
| 469 | |
| 470 | if (windowId === 'profiler') { |
| 471 | setShowProfiler(true); |
| 472 | } else if (windowId === 'advancedProfiler') { |
| 473 | setShowAdvancedProfiler(true); |
| 474 | } else if (windowId === 'pluginManager') { |
| 475 | // 插件管理现在整合到设置窗口中 |
| 476 | setSettingsInitialCategory('plugins'); |
| 477 | setShowSettings(true); |
| 478 | } |
| 479 | }); |
| 480 | |
| 481 | // 设置服务引用(不触发重渲染)| Set service refs (no re-renders) |
| 482 | pluginManagerRef.current = services.pluginManager; |
| 483 | entityStoreRef.current = services.entityStore; |
| 484 | messageHubRef.current = services.messageHub; |
| 485 | inspectorRegistryRef.current = services.inspectorRegistry; |
| 486 | logServiceRef.current = services.logService; |
| 487 | uiRegistryRef.current = services.uiRegistry; |
| 488 | settingsRegistryRef.current = services.settingsRegistry; |
| 489 | sceneManagerRef.current = services.sceneManager; |
| 490 | notificationRef.current = services.notification; |
| 491 | dialogRef.current = services.dialog as IDialogExtended; |
| 492 | buildServiceRef.current = services.buildService; |
| 493 | |
| 494 | // 设置初始化完成(触发一次重渲染)| Set initialized (triggers one re-render) |
| 495 | setInitialized(true); |
| 496 | setStatus(t('header.status.ready')); |
no test coverage detected