From 7f64e1c4b9ed253e0bc0a979b0b5999cfa02de38 Mon Sep 17 00:00:00 2001 From: panw Date: Wed, 31 Dec 2025 16:43:47 +0800 Subject: [PATCH] =?UTF-8?q?refactor(hero):=20=E7=AE=80=E5=8C=96=E6=8A=A4?= =?UTF-8?q?=E7=9B=BE=E6=98=BE=E7=A4=BA=E9=80=BB=E8=BE=91=E5=B9=B6=E7=A7=BB?= =?UTF-8?q?=E9=99=A4=E5=86=97=E4=BD=99=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 移除对top_node活跃状态的冗余检查,直接使用其活跃状态作为前置条件 合并护盾显示的条件判断,简化进度条更新逻辑 --- assets/script/game/hero/HeroViewComp.ts | 28 +++++++------------------ 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/assets/script/game/hero/HeroViewComp.ts b/assets/script/game/hero/HeroViewComp.ts index 97f12ba3..b03a620f 100644 --- a/assets/script/game/hero/HeroViewComp.ts +++ b/assets/script/game/hero/HeroViewComp.ts @@ -170,26 +170,14 @@ export class HeroViewComp extends CCComp { /** 显示护盾 */ private show_shield(shield: number = 0, shield_max: number = 0) { - // ✅ 即使 top_node 不活跃,也要更新护盾的显示状态 - // 当护盾为0时,隐藏护盾UI - const hasShield = shield > 0 && shield_max > 0; - - this.node.getChildByName("shielded").active = hasShield; - - // 如果 top_node 活跃,才更新护盾进度条 - if (this.top_node) { - this.top_node.getChildByName("shield").active = hasShield; - - if (hasShield) { - let shield_progress = shield / shield_max; - this.top_node.getChildByName("shield").getComponent(ProgressBar).progress = shield_progress; - this.scheduleOnce(() => { - if (this.top_node && this.top_node.isValid) { - this.top_node.getChildByName("shield").getChildByName("pb").getComponent(ProgressBar).progress = shield_progress; - } - }, 0.15); - } - } + if(!this.top_node.active) return + let shield_progress = shield / shield_max; + this.node.getChildByName("shielded").active = shield > 0; + this.top_node.getChildByName("shield").active = shield > 0; + this.top_node.getChildByName("shield").getComponent(ProgressBar).progress = shield_progress; + this.scheduleOnce(() => { + this.top_node.getChildByName("shield").getChildByName("pb").getComponent(ProgressBar).progress = shield_progress; + }, 0.15); } /** 显示血量 */