From 4fc6652dfd1f1249c9a2ad5a4ac75472d1d64a99 Mon Sep 17 00:00:00 2001 From: dgflash Date: Sat, 13 Jun 2026 15:32:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=8F=91=E5=B8=83=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F=E4=B8=8B=E7=B1=BB=E5=90=8D=E6=B7=B7=E6=B7=86=E5=AF=BC?= =?UTF-8?q?=E8=87=B4addBusinesss=E5=B1=9E=E6=80=A7=E7=BB=91=E5=AE=9A?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/module/common/CCEntity.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/assets/module/common/CCEntity.ts b/assets/module/common/CCEntity.ts index b1325ea..15540ee 100644 --- a/assets/module/common/CCEntity.ts +++ b/assets/module/common/CCEntity.ts @@ -296,12 +296,22 @@ export abstract class CCEntity extends ecs.Entity { this.businesss.delete(cls); // 清理实体上的业务逻辑组件引用 - delete (this as any)[cls.name]; + this.deleteBusinessRef(business); } } } //#endregion + /** 删除实体上指向指定 business 实例的属性引用 */ + private deleteBusinessRef(business: CCBusiness) { + for (const key of Object.keys(this)) { + if ((this as any)[key] === business) { + delete (this as any)[key]; + break; + } + } + } + destroy(): void { // 1. 先销毁所有子实体,避免内存泄漏 if (this.singletons) { @@ -317,10 +327,10 @@ export abstract class CCEntity extends ecs.Entity { // 2. 再销毁所有业务组件 if (this.businesss) { - this.businesss.forEach((business, cls) => { + this.businesss.forEach((business) => { business.destroy(); // 清理实体上的业务逻辑组件引用 - delete (this as any)[cls.name]; + this.deleteBusinessRef(business); }); this.businesss.clear(); this.businesss = null!;