Feature/UI input system fix (#243)
* feat(ui): 实现编辑器预览模式下的 UI 输入系统 * feat(platform-web): 为浏览器运行时添加 UI 输入系统绑定
This commit is contained in:
@@ -9,7 +9,7 @@ import { EngineBridge, EngineRenderSystem, CameraSystem } from '@esengine/ecs-en
|
||||
import { TransformComponent, SpriteAnimatorSystem, CoreRuntimeModule } from '@esengine/ecs-components';
|
||||
import type { SystemContext, IPluginLoader, IRuntimeModuleLoader, PluginDescriptor } from '@esengine/ecs-components';
|
||||
// Import from /runtime entry points to avoid editor dependencies (React, etc.)
|
||||
import { UIRuntimeModule, UIRenderDataProvider } from '@esengine/ui/runtime';
|
||||
import { UIRuntimeModule, UIRenderDataProvider, UIInputSystem } from '@esengine/ui/runtime';
|
||||
import { TilemapRuntimeModule, TilemapRenderingSystem } from '@esengine/tilemap/runtime';
|
||||
import { BehaviorTreeRuntimeModule, BehaviorTreeExecutionSystem } from '@esengine/behavior-tree/runtime';
|
||||
|
||||
@@ -33,6 +33,8 @@ export interface RuntimeModuleConfig {
|
||||
enabledPlugins?: string[];
|
||||
/** 是否为编辑器模式 */
|
||||
isEditor?: boolean;
|
||||
/** Canvas ID 用于 UI 输入绑定 */
|
||||
canvasId?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -352,6 +354,15 @@ export function createRuntimeSystems(
|
||||
|
||||
scene.addSystem(renderSystem);
|
||||
|
||||
// 绑定 UIInputSystem 到 canvas(用于 UI 交互)
|
||||
// Bind UIInputSystem to canvas (for UI interaction)
|
||||
if (config?.canvasId && context.uiInputSystem) {
|
||||
const canvas = document.getElementById(config.canvasId) as HTMLCanvasElement;
|
||||
if (canvas) {
|
||||
(context.uiInputSystem as UIInputSystem).bindToCanvas(canvas);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
cameraSystem,
|
||||
animatorSystem: context.animatorSystem as SpriteAnimatorSystem | undefined,
|
||||
|
||||
@@ -21,8 +21,10 @@ class BrowserRuntime {
|
||||
private animationId: number | null = null;
|
||||
private assetManager: AssetManager;
|
||||
private engineIntegration: EngineIntegration;
|
||||
private canvasId: string;
|
||||
|
||||
constructor(config: RuntimeConfig) {
|
||||
this.canvasId = config.canvasId;
|
||||
if (!Core.Instance) {
|
||||
Core.create();
|
||||
}
|
||||
@@ -58,8 +60,10 @@ class BrowserRuntime {
|
||||
// 初始化模块系统
|
||||
await initializeRuntime(Core);
|
||||
|
||||
// 创建运行时系统
|
||||
this.systems = createRuntimeSystems(Core.scene!, this.bridge);
|
||||
// 创建运行时系统(传入 canvasId 用于 UI 输入绑定)
|
||||
this.systems = createRuntimeSystems(Core.scene!, this.bridge, {
|
||||
canvasId: this.canvasId
|
||||
});
|
||||
}
|
||||
|
||||
async loadScene(sceneUrl: string): Promise<void> {
|
||||
|
||||
Reference in New Issue
Block a user