From 1e0537b63d172b4d3faaaae31d5040265896e707 Mon Sep 17 00:00:00 2001 From: panw Date: Tue, 4 Nov 2025 11:12:43 +0800 Subject: [PATCH] =?UTF-8?q?refactor(hero):=20=E4=BC=98=E5=8C=96=E6=80=AA?= =?UTF-8?q?=E7=89=A9=E7=94=9F=E6=88=90=E4=BD=8D=E7=BD=AE=E8=AE=A1=E7=AE=97?= =?UTF-8?q?=E5=B9=B6=E6=B7=BB=E5=8A=A0=E8=B0=83=E8=AF=95=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 使用 MonStart 配置计算怪物出生位置,替代硬编码的 MonSet - 添加 console.log 调试英雄和怪物的 siblingIndex - 根据 y 坐标动态判断线路,提高代码可读性和可维护性 --- assets/script/game/hero/Hero.ts | 3 ++- assets/script/game/hero/Mon.ts | 2 +- assets/script/game/map/MissionMonComp.ts | 13 +++++++++---- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/assets/script/game/hero/Hero.ts b/assets/script/game/hero/Hero.ts index b78c63bd..33b7fba4 100644 --- a/assets/script/game/hero/Hero.ts +++ b/assets/script/game/hero/Hero.ts @@ -55,7 +55,8 @@ export class Hero extends ecs.Entity { // 🔥 设置初始 SiblingIndex - 英雄基础层级 + 位置偏移 const initialSiblingIndex = IndexSet.HERO; node.setSiblingIndex(initialSiblingIndex); - + console.log("hero",node.getSiblingIndex()); + // console.log("hero load",pos) var hv = node.getComponent(HeroViewComp)!; const model = this.get(HeroAttrsComp); diff --git a/assets/script/game/hero/Mon.ts b/assets/script/game/hero/Mon.ts index ad5c8097..fc09b407 100644 --- a/assets/script/game/hero/Mon.ts +++ b/assets/script/game/hero/Mon.ts @@ -55,7 +55,7 @@ export class Monster extends ecs.Entity { const safeSpawnOrder = spawnOrder % 999; // 限制在999以内,避免溢出到其他层级 const initialSiblingIndex = baseLane + safeSpawnOrder; node.setSiblingIndex(initialSiblingIndex); - + console.log("mon",node.getSiblingIndex()); var view = node.getComponent(HeroViewComp)!; const model = this.get(HeroAttrsComp); const skillsComp = this.get(HeroSkillsComp); diff --git a/assets/script/game/map/MissionMonComp.ts b/assets/script/game/map/MissionMonComp.ts index 6cb509c8..eb205bb7 100644 --- a/assets/script/game/map/MissionMonComp.ts +++ b/assets/script/game/map/MissionMonComp.ts @@ -2,7 +2,7 @@ import { _decorator, v3, Vec3 } from "cc"; import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS"; import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp"; import { Monster } from "../hero/Mon"; -import { MonSet } from "../common/config/heroSet"; +import { MonStart } from "../common/config/heroSet"; import { smc } from "../common/SingletonModuleComp"; import { GameEvent } from "../common/config/GameEvent"; // 导入肉鸽配置 @@ -189,10 +189,15 @@ export class MissionMonCompComp extends CCComp { ) { let mon = ecs.getEntity(Monster); let scale = -1; - let pos: Vec3 = v3(MonSet[i].pos); + // 使用 MonStart 计算怪物出生位置: + // x 从 START_X 开始,按 START_I 的间隔递增; + // y 在线路之间交替:偶数索引为 SLINE_1,奇数索引为 SLINE_2。 + const x = MonStart.START_X + Math.floor(i / 2) * MonStart.START_I; + const y = (i % 2 === 0) ? MonStart.SLINE_1 : MonStart.SLINE_2; + let pos: Vec3 = v3(x, y, 0); - // 根据位置判断线路:y=110为一线(lane=0),y=80为二线(lane=1) - const lane = pos.y === 130 ? 0 : 1; + // 根据位置判断线路:y=SLINE_1 为一线(lane=0),y=SLINE_2 为二线(lane=1) + const lane = y === MonStart.SLINE_1 ? 0 : 1; // 递增全局生成顺序 - 🔥 添加溢出保护 this.globalSpawnOrder = (this.globalSpawnOrder + 1) % 999; // 防止无限增长,在999处循环重置