From e1e156fa5b93e6ff9dfab658b64a00a08d73d3de Mon Sep 17 00:00:00 2001 From: panw Date: Wed, 31 Dec 2025 15:51:06 +0800 Subject: [PATCH] =?UTF-8?q?refactor(hero):=20=E7=A7=BB=E9=99=A4=E8=A7=86?= =?UTF-8?q?=E5=9B=BE=E5=B1=82=E7=9B=B4=E6=8E=A5=E6=9B=B4=E6=96=B0=E9=80=BB?= =?UTF-8?q?=E8=BE=91=EF=BC=8C=E4=BD=BF=E7=94=A8=E8=84=8F=E6=A0=87=E7=AD=BE?= =?UTF-8?q?=E6=9C=BA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在HeroViewComp中移除hp_show和mp_show的直接调用 - 在HeroAttrsComp中不再直接调用视图层方法 - 使用脏标签机制(dirty flag)来触发UI更新 --- assets/script/game/hero/HeroAttrsComp.ts | 27 ++++++++++++++---------- assets/script/game/hero/HeroViewComp.ts | 19 +++++++++++------ 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/assets/script/game/hero/HeroAttrsComp.ts b/assets/script/game/hero/HeroAttrsComp.ts index 16745d05..3cf83e52 100644 --- a/assets/script/game/hero/HeroAttrsComp.ts +++ b/assets/script/game/hero/HeroAttrsComp.ts @@ -3,7 +3,6 @@ import { Attrs, AttrsType, BType, NeAttrs } from "../common/config/HeroAttrs"; import { BuffConf } from "../common/config/SkillSet"; import { HeroInfo, AttrSet } from "../common/config/heroSet"; import { HeroSkillsComp } from "./HeroSkills"; -import { HeroViewComp } from "./HeroViewComp"; interface talTrigger{ @@ -127,26 +126,32 @@ export class HeroAttrsComp extends ecs.Comp { if(!isValue){ addValue = value * this.Attrs[Attrs.HP_MAX] / 100; } - let heroView = this.ent.get(HeroViewComp); - if(heroView){ - heroView.health(addValue); - } + + // ✅ 数据层只负责数据修改,不调用视图层 + // let heroView = this.ent.get(HeroViewComp); + // if(heroView){ + // heroView.health(addValue); + // } + this.hp += addValue; this.hp = Math.max(0, Math.min(this.hp, this.Attrs[Attrs.HP_MAX])); - this.dirty_hp = true; // 标记血量需要更新 + this.dirty_hp = true; // ✅ 仅标记需要更新 } add_mp(value:number,isValue:boolean){ let addValue = value; if(!isValue){ addValue = value * this.Attrs[Attrs.MP_MAX] / 100; } - let heroView = this.ent.get(HeroViewComp); - if(heroView){ - heroView.mp_add(addValue); - } + + // ✅ 数据层只负责数据修改,不调用视图层 + // let heroView = this.ent.get(HeroViewComp); + // if(heroView){ + // heroView.mp_add(addValue); + // } + this.mp += addValue; this.mp = Math.max(0, Math.min(this.mp, this.Attrs[Attrs.MP_MAX])); - this.dirty_mp = true; // 标记魔法值需要更新 + this.dirty_mp = true; // ✅ 仅标记需要更新 } add_shield(value:number,isValue:boolean){ let addValue = value; diff --git a/assets/script/game/hero/HeroViewComp.ts b/assets/script/game/hero/HeroViewComp.ts index cf66f441..b6c3bbc2 100644 --- a/assets/script/game/hero/HeroViewComp.ts +++ b/assets/script/game/hero/HeroViewComp.ts @@ -81,7 +81,7 @@ export class HeroViewComp extends CCComp { collider.enabled = true; // 先禁 collider.group = this.box_group; // 设置为英雄组 } - + },0.1) // let anm = this.node.getChildByName("anm") // anm.setScale(anm.scale.x*0.8,anm.scale.y*0.8); @@ -312,17 +312,22 @@ export class HeroViewComp extends CCComp { } health(hp: number = 0) { - // 生命值更新由 Model 层处理,这里只负责视图表现 + // ✅ 仅显示特效和提示,不调用 hp_show() this.heathed(); this.hp_tip(TooltipTypes.health, hp.toFixed(0)); - this.top_node.active=true - this.hp_show(); + this.top_node.active = true; + + // ❌ 移除:UI更新由脏标签机制处理 + // this.hp_show(); } + mp_add(mp: number = 0) { - // 生命值更新由 Model 层处理,这里只负责视图表现 + // ✅ 仅显示提示,不调用 mp_show() this.hp_tip(TooltipTypes.addmp, mp.toFixed(0)); - this.top_node.active=true - this.mp_show(); + this.top_node.active = true; + + // ❌ 移除:UI更新由脏标签机制处理 + // this.mp_show(); } alive(){