From 9ab8ccdb92ab54cab57c6f5fe304a0b9fe94275d Mon Sep 17 00:00:00 2001 From: walkpan Date: Sun, 4 Jan 2026 22:24:54 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E7=BB=84=E4=BB=B6):=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E7=BB=84=E4=BB=B6=E9=94=80=E6=AF=81=E6=97=B6=E7=9A=84?= =?UTF-8?q?=E8=B5=84=E6=BA=90=E6=B8=85=E7=90=86=E9=80=BB=E8=BE=91=E5=B9=B6?= =?UTF-8?q?=E7=A7=BB=E9=99=A4=E6=97=A0=E7=94=A8=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在TopComp、move和HeroAnmComp组件中添加onDestroy方法,用于清理事件监听 移除已不再使用的MInfoComp组件及其meta文件 --- assets/script/game/hero/HeroAnmComp.ts | 6 ++++++ assets/script/game/map/MInfoComp.ts | 27 ------------------------ assets/script/game/map/MInfoComp.ts.meta | 9 -------- assets/script/game/map/TopComp.ts | 4 ++++ assets/script/game/map/move.ts | 6 ++++++ 5 files changed, 16 insertions(+), 36 deletions(-) delete mode 100644 assets/script/game/map/MInfoComp.ts delete mode 100644 assets/script/game/map/MInfoComp.ts.meta diff --git a/assets/script/game/hero/HeroAnmComp.ts b/assets/script/game/hero/HeroAnmComp.ts index 0e0c1ea0..0d6a66be 100644 --- a/assets/script/game/hero/HeroAnmComp.ts +++ b/assets/script/game/hero/HeroAnmComp.ts @@ -17,6 +17,12 @@ export default class HeroAnmComp extends Component{ this.anmcon.on(Animation.EventType.FINISHED, this.onAnimationFinished, this); } + onDestroy() { + if (this.anmcon) { + this.anmcon.off(Animation.EventType.FINISHED, this.onAnimationFinished, this); + } + } + stop () { this._hasStop = true; diff --git a/assets/script/game/map/MInfoComp.ts b/assets/script/game/map/MInfoComp.ts deleted file mode 100644 index 86aff305..00000000 --- a/assets/script/game/map/MInfoComp.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { _decorator, Component, Label, Node } from 'cc'; -import { oops } from 'db://oops-framework/core/Oops'; -import { GameEvent } from '../common/config/GameEvent'; -import { smc } from '../common/SingletonModuleComp'; -const { ccclass, property } = _decorator; - -@ccclass('MInfoComp') -export class MInfoComp extends Component { - protected onLoad(): void { - oops.message.on(GameEvent.MISSION_UPDATE,this.onMissionUpdate,this); - this.update_mission(smc.data.mission) - } - start() { - this.update_mission(smc.data.mission) - } - onMissionUpdate(event:string,data:any){ - this.update_mission(smc.data.mission) - } - - update_mission(mission:number){ - this.node.getChildByName("mission").getComponent(Label).string="第 "+mission.toString()+" 关" - } - - -} - - diff --git a/assets/script/game/map/MInfoComp.ts.meta b/assets/script/game/map/MInfoComp.ts.meta deleted file mode 100644 index f518ccf8..00000000 --- a/assets/script/game/map/MInfoComp.ts.meta +++ /dev/null @@ -1,9 +0,0 @@ -{ - "ver": "4.0.24", - "importer": "typescript", - "imported": true, - "uuid": "45cb2edd-7958-45ba-8eb9-bcf587448e5c", - "files": [], - "subMetas": {}, - "userData": {} -} diff --git a/assets/script/game/map/TopComp.ts b/assets/script/game/map/TopComp.ts index 4f094a15..c90afe63 100644 --- a/assets/script/game/map/TopComp.ts +++ b/assets/script/game/map/TopComp.ts @@ -20,6 +20,10 @@ export class topComp extends Component { .start() } + onDestroy(){ + oops.message.off(GameEvent.GOLD_UPDATE,this.onGoldUpdate,this); + } + update(deltaTime: number) { diff --git a/assets/script/game/map/move.ts b/assets/script/game/map/move.ts index 494e6c4c..29253780 100644 --- a/assets/script/game/map/move.ts +++ b/assets/script/game/map/move.ts @@ -37,6 +37,12 @@ export class move extends Component { this.setInitialPosition() } } + + onDestroy() { + oops.message.off(GameEvent.MAP_MOVE_END_LEFT, this.onMapMoveEndLeft, this); + oops.message.off(GameEvent.MAP_MOVE_END_RIGHT, this.onMapMoveEndRight, this); + } + /** * 根据移动方向设置初始位置 */