From a332b8f2c966d6d45837a060a062a7ba8db57e75 Mon Sep 17 00:00:00 2001 From: panw Date: Wed, 13 May 2026 17:31:08 +0800 Subject: [PATCH] refactor(mission card): optimize hero position transfer logic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 重构了英雄位置更新的处理逻辑,先收集所有需要转移的英雄再统一处理,同时增加了节点复用和提前隐藏旧节点的逻辑,避免多英雄位置更新时的数据冲突和节点占用问题。 --- assets/script/game/map/MissionCardComp.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/assets/script/game/map/MissionCardComp.ts b/assets/script/game/map/MissionCardComp.ts index 409cf3a8..e2f474f2 100644 --- a/assets/script/game/map/MissionCardComp.ts +++ b/assets/script/game/map/MissionCardComp.ts @@ -966,14 +966,21 @@ export class MissionCardComp extends CCComp { } // 2. 然后再处理所有存活英雄的位置转移和信息刷新 - // 如果有多个英雄在同一帧发生位置变动,可能会出现目标节点暂时被其他还没更新的英雄占用的情况, - // 为了防止数据互相覆盖,我们先将需要转移的英雄收集起来。 + // 如果有多个英雄在同一帧发生位置变动,我们需要统一处理 const needTransfer: Array<{eid: number, expectedNodeIndex: number}> = []; this.heroInfoItems.forEach((item, eid) => { + // 检查英雄是否改变了位置 (lane 或 lane_index 发生了变化) const expectedNodeIndex = item.model.lane_index * 3 + item.model.lane + 1; + if (item.comp.node_index !== expectedNodeIndex) { - needTransfer.push({eid, expectedNodeIndex}); + // 如果位置变了,需要转移到新的节点上 + const newComp = this.cachedHInfoComps.get(expectedNodeIndex); + if (newComp) { + needTransfer.push({eid, expectedNodeIndex}); + // 将原来的节点释放,以供其他可能换到这个位置的英雄使用 + item.node.active = false; + } } else { this.updateHeroInfoPanel(item); } @@ -986,8 +993,6 @@ export class MissionCardComp extends CCComp { const newComp = this.cachedHInfoComps.get(transfer.expectedNodeIndex); if (newComp) { - // 隐藏旧节点 - item.node.active = false; // 转移到新节点 item.comp = newComp; item.node = newComp.node;