From 9c1bf8dbed98c861c63a5f0d817855f9ae1159e9 Mon Sep 17 00:00:00 2001 From: YHH <359807859@qq.com> Date: Sat, 1 Nov 2025 18:19:23 +0800 Subject: [PATCH] =?UTF-8?q?refactor(core):=20=E7=A7=BB=E9=99=A4=E5=85=A8?= =?UTF-8?q?=E5=B1=80EventBus=EF=BC=8C=E5=AE=9E=E7=8E=B0=E5=9C=BA=E6=99=AF?= =?UTF-8?q?=E7=BA=A7=E4=BA=8B=E4=BB=B6=E9=9A=94=E7=A6=BB=20(#211)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/src/ECS/Entity.ts | 15 ++++----------- packages/core/src/ECS/Scene.ts | 11 ----------- 2 files changed, 4 insertions(+), 22 deletions(-) diff --git a/packages/core/src/ECS/Entity.ts b/packages/core/src/ECS/Entity.ts index 18581fec..23fb4c1e 100644 --- a/packages/core/src/ECS/Entity.ts +++ b/packages/core/src/ECS/Entity.ts @@ -1,6 +1,5 @@ import { Component } from './Component'; import { ComponentRegistry, ComponentType } from './Core/ComponentStorage'; -import { EventBus } from './Core/EventBus'; import { BitMask64Utils, BitMask64Data } from './Utils/BigIntCompatibility'; import { createLogger } from '../Utils/Logger'; import { getComponentInstanceTypeName, getComponentTypeName } from './Decorators'; @@ -70,12 +69,6 @@ export class Entity { */ public static entityComparer: EntityComparer = new EntityComparer(); - /** - * 全局事件总线实例 - * 用于发射组件相关事件 - */ - public static eventBus: EventBus | null = null; - /** * 实体名称 */ @@ -428,8 +421,8 @@ export class Entity { } component.onAddedToEntity(); - if (Entity.eventBus) { - Entity.eventBus.emitComponentAdded({ + if (this.scene && this.scene.eventSystem) { + this.scene.eventSystem.emitSync('component:added', { timestamp: Date.now(), source: 'Entity', entityId: this.id, @@ -561,8 +554,8 @@ export class Entity { component.entityId = null; - if (Entity.eventBus) { - Entity.eventBus.emitComponentRemoved({ + if (this.scene && this.scene.eventSystem) { + this.scene.eventSystem.emitSync('component:removed', { timestamp: Date.now(), source: 'Entity', entityId: this.id, diff --git a/packages/core/src/ECS/Scene.ts b/packages/core/src/ECS/Scene.ts index 5a6837ad..89f2c2ed 100644 --- a/packages/core/src/ECS/Scene.ts +++ b/packages/core/src/ECS/Scene.ts @@ -5,7 +5,6 @@ import { EntitySystem } from './Systems/EntitySystem'; import { ComponentStorageManager, ComponentRegistry, ComponentType } from './Core/ComponentStorage'; import { QuerySystem } from './Core/QuerySystem'; import { TypeSafeEventSystem } from './Core/EventSystem'; -import { EventBus } from './Core/EventBus'; import { ReferenceTracker } from './Core/ReferenceTracker'; import { IScene, ISceneConfig } from './IScene'; import { getComponentInstanceTypeName, getSystemInstanceTypeName, getSystemMetadata } from './Decorators'; @@ -245,16 +244,6 @@ export class Scene implements IScene { if (config?.name) { this.name = config.name; } - - if (!Entity.eventBus) { - Entity.eventBus = new EventBus(false); - } - - if (Entity.eventBus) { - Entity.eventBus.onComponentAdded((data: unknown) => { - this.eventSystem.emitSync('component:added', data); - }); - } } /**