refactor(组件): 添加组件销毁时的资源清理逻辑并移除无用文件
在TopComp、move和HeroAnmComp组件中添加onDestroy方法,用于清理事件监听 移除已不再使用的MInfoComp组件及其meta文件
This commit is contained in:
@@ -17,6 +17,12 @@ export default class HeroAnmComp extends Component{
|
|||||||
this.anmcon.on(Animation.EventType.FINISHED, this.onAnimationFinished, this);
|
this.anmcon.on(Animation.EventType.FINISHED, this.onAnimationFinished, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onDestroy() {
|
||||||
|
if (this.anmcon) {
|
||||||
|
this.anmcon.off(Animation.EventType.FINISHED, this.onAnimationFinished, this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
stop () {
|
stop () {
|
||||||
this._hasStop = true;
|
this._hasStop = true;
|
||||||
|
|||||||
@@ -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()+" 关"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
{
|
|
||||||
"ver": "4.0.24",
|
|
||||||
"importer": "typescript",
|
|
||||||
"imported": true,
|
|
||||||
"uuid": "45cb2edd-7958-45ba-8eb9-bcf587448e5c",
|
|
||||||
"files": [],
|
|
||||||
"subMetas": {},
|
|
||||||
"userData": {}
|
|
||||||
}
|
|
||||||
@@ -20,6 +20,10 @@ export class topComp extends Component {
|
|||||||
.start()
|
.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onDestroy(){
|
||||||
|
oops.message.off(GameEvent.GOLD_UPDATE,this.onGoldUpdate,this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
update(deltaTime: number) {
|
update(deltaTime: number) {
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,12 @@ export class move extends Component {
|
|||||||
this.setInitialPosition()
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据移动方向设置初始位置
|
* 根据移动方向设置初始位置
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user