diff --git a/assets/script/game/map/MissionCardComp.ts b/assets/script/game/map/MissionCardComp.ts index 82d1e467..cd4bfc3a 100644 --- a/assets/script/game/map/MissionCardComp.ts +++ b/assets/script/game/map/MissionCardComp.ts @@ -167,7 +167,7 @@ export class MissionCardComp extends CCComp { this.cacheCardComps(); this.layoutCardSlots(); this.initCardsPanelPos(); - this.onMissionStart(); + // this.onMissionStart(); // 移除 onLoad 自动触发,改为事件驱动 mLogger.log(this.debugMode, "MissionCardComp", "onLoad init", { slots: this.cardComps.length, poolLv: this.poolLv @@ -231,7 +231,9 @@ export class MissionCardComp extends CCComp { // this.resetButtonScale(this.cards_up); this.updateCoinAndCostUI(); this.updateHeroNumUI(false, false); - this.node.active = true; + if (this.node && this.node.isValid) { + this.node.active = true; + } const cards = this.buildDrawCards(); this.dispatchCardsToSlots(cards); mLogger.log(this.debugMode, "MissionCardComp", "mission start", { @@ -243,7 +245,9 @@ export class MissionCardComp extends CCComp { onMissionEnd() { this.clearAllCards(); this.clearHeroInfoPanels(); - this.node.active = false; + if (this.node && this.node.isValid) { + this.node.active = false; + } } start() { @@ -264,7 +268,9 @@ export class MissionCardComp extends CCComp { /** 关闭面板(不销毁数据模型,仅隐藏) */ close() { - this.node.active = false; + if (this.node && this.node.isValid) { + this.node.active = false; + } } // ======================== 事件绑定 ======================== diff --git a/assets/script/game/map/MissionComp.ts b/assets/script/game/map/MissionComp.ts index af7ec7d6..6db07d01 100644 --- a/assets/script/game/map/MissionComp.ts +++ b/assets/script/game/map/MissionComp.ts @@ -189,9 +189,12 @@ export class MissionComp extends CCComp { } onAdded(args: any) { - // UI加载完成后,抛出MissionStart事件,启动战斗(触发自身 mission_start 及其他系统) - oops.message.dispatchEvent(GameEvent.MissionStart, {}); - this.mission_start(); + // 使用 scheduleOnce 将事件推迟到下一帧执行, + // 确保所有关联组件(如 MissionCardComp 等)都已经完成其 onLoad 生命周期。 + this.scheduleOnce(() => { + oops.message.dispatchEvent(GameEvent.MissionStart, {}); + this.mission_start(); + }, 0); } onDestroy(){ @@ -244,7 +247,13 @@ export class MissionComp extends CCComp { if (this.isBossWave) { const str = "∞"; if (str != this.lastTimeStr) { - this.time_node.getChildByName("time").getComponent(Label).string = str; + if (this.time_node && this.time_node.isValid) { + const timeChild = this.time_node.getChildByName("time"); + if (timeChild) { + const label = timeChild.getComponent(Label); + if (label) label.string = str; + } + } this.lastTimeStr = str; this.lastTimeSecond = -1; } @@ -260,7 +269,13 @@ export class MissionComp extends CCComp { const wave = Math.max(1, this.currentWave || smc.vmdata.mission_data.level || 1); let str = `${m.toString().padStart(2, '0')}:${s.toString().padStart(2, '0')}`; if(str != this.lastTimeStr){ - this.time_node.getChildByName("time").getComponent(Label).string = str; + if (this.time_node && this.time_node.isValid) { + const timeChild = this.time_node.getChildByName("time"); + if (timeChild) { + const label = timeChild.getComponent(Label); + if (label) label.string = str; + } + } this.lastTimeStr = str; } }