refactor(hero): 简化护盾显示逻辑并移除冗余检查
移除对top_node活跃状态的冗余检查,直接使用其活跃状态作为前置条件 合并护盾显示的条件判断,简化进度条更新逻辑
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
/** 显示血量 */
|
||||
|
||||
Reference in New Issue
Block a user