From 4db87885897ae8bc7b6bb7ea80039dbceed2c10e Mon Sep 17 00:00:00 2001 From: panw Date: Mon, 16 Mar 2026 10:15:03 +0800 Subject: [PATCH] =?UTF-8?q?fix(SkillView):=20=E6=8F=90=E5=89=8D=E6=A3=80?= =?UTF-8?q?=E6=9F=A5=E5=91=BD=E4=B8=AD=E6=AC=A1=E6=95=B0=E5=B9=B6=E7=AB=8B?= =?UTF-8?q?=E5=8D=B3=E5=85=B3=E9=97=AD=E7=A2=B0=E6=92=9E=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在碰撞检测开始时立即检查命中次数,达到上限后立即关闭碰撞器并返回,避免后续不必要的逻辑执行。同时移除后续重复的命中次数检查和关闭碰撞器逻辑,简化代码结构。 --- assets/script/game/skill/SkillView.ts | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/assets/script/game/skill/SkillView.ts b/assets/script/game/skill/SkillView.ts index 83fb0a59..4b6a46eb 100644 --- a/assets/script/game/skill/SkillView.ts +++ b/assets/script/game/skill/SkillView.ts @@ -74,6 +74,14 @@ export class SkillView extends CCComp { mLogger.log(this.debugMode, 'SkillView', `[skillView] 碰撞1 [${this.sData.caster.box_group}][${casterName}][${casterEid}]的[${seCol.group}]:[${this.SConf.name}][${this.ent.eid}]碰撞了 [${oCol.group}]:[ ${targetName}][${targetEid}]`); if (oCol.group === seCol.group) return; if (this.pendingDisableCollider) return; + if (this.sData.hit_count >= this.sData.max_hit_count) { + this.close_collider(); + return; + } + this.sData.hit_count++; + if (this.sData.hit_count >= this.sData.max_hit_count) { + this.close_collider(); + } // 不是 HeroViewComp,直接忽略 if (!targetView) return; // 🔥 方案A:防御性检查 - 在获取model前强制检查ent是否存在 @@ -116,11 +124,6 @@ export class SkillView extends CCComp { if (!target.ent) return; if (!this.sData) return; if (!this.SConf) return; - // 检查技能是否应该销毁 - if ( this.sData.hit_count >= this.sData.max_hit_count ) { - this.close_collider() - return - } // 安全获取名称,防止实体销毁导致的空指针异常 const casterName = this.sData.caster?.ent?.get(HeroAttrsComp)?.hero_name ?? "未知施法者"; const targetName = target.ent.get(HeroAttrsComp)?.hero_name ?? "未知目标"; @@ -135,12 +138,6 @@ export class SkillView extends CCComp { this.sData.ext_dmg, this.sData.dmg_ratio, ); - - // 更新技能命中次数 - this.sData.hit_count++ - if (this.sData.hit_count >= this.sData.max_hit_count) { - this.close_collider(); - } if ( (this.SConf.DTType != DTType.range) && (this.SConf.EType != EType.animationEnd) &&