refactor(hero): 优化怪物生成位置计算并添加调试日志

- 使用 MonStart 配置计算怪物出生位置,替代硬编码的 MonSet
- 添加 console.log 调试英雄和怪物的 siblingIndex
- 根据 y 坐标动态判断线路,提高代码可读性和可维护性
This commit is contained in:
2025-11-04 11:12:43 +08:00
parent fc637529e2
commit 1e0537b63d
3 changed files with 12 additions and 6 deletions

View File

@@ -55,7 +55,8 @@ export class Hero extends ecs.Entity {
// 🔥 设置初始 SiblingIndex - 英雄基础层级 + 位置偏移 // 🔥 设置初始 SiblingIndex - 英雄基础层级 + 位置偏移
const initialSiblingIndex = IndexSet.HERO; const initialSiblingIndex = IndexSet.HERO;
node.setSiblingIndex(initialSiblingIndex); node.setSiblingIndex(initialSiblingIndex);
console.log("hero",node.getSiblingIndex());
// console.log("hero load",pos) // console.log("hero load",pos)
var hv = node.getComponent(HeroViewComp)!; var hv = node.getComponent(HeroViewComp)!;
const model = this.get(HeroAttrsComp); const model = this.get(HeroAttrsComp);

View File

@@ -55,7 +55,7 @@ export class Monster extends ecs.Entity {
const safeSpawnOrder = spawnOrder % 999; // 限制在999以内避免溢出到其他层级 const safeSpawnOrder = spawnOrder % 999; // 限制在999以内避免溢出到其他层级
const initialSiblingIndex = baseLane + safeSpawnOrder; const initialSiblingIndex = baseLane + safeSpawnOrder;
node.setSiblingIndex(initialSiblingIndex); node.setSiblingIndex(initialSiblingIndex);
console.log("mon",node.getSiblingIndex());
var view = node.getComponent(HeroViewComp)!; var view = node.getComponent(HeroViewComp)!;
const model = this.get(HeroAttrsComp); const model = this.get(HeroAttrsComp);
const skillsComp = this.get(HeroSkillsComp); const skillsComp = this.get(HeroSkillsComp);

View File

@@ -2,7 +2,7 @@ import { _decorator, v3, Vec3 } from "cc";
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS"; import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp"; import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
import { Monster } from "../hero/Mon"; import { Monster } from "../hero/Mon";
import { MonSet } from "../common/config/heroSet"; import { MonStart } from "../common/config/heroSet";
import { smc } from "../common/SingletonModuleComp"; import { smc } from "../common/SingletonModuleComp";
import { GameEvent } from "../common/config/GameEvent"; import { GameEvent } from "../common/config/GameEvent";
// 导入肉鸽配置 // 导入肉鸽配置
@@ -189,10 +189,15 @@ export class MissionMonCompComp extends CCComp {
) { ) {
let mon = ecs.getEntity<Monster>(Monster); let mon = ecs.getEntity<Monster>(Monster);
let scale = -1; 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) // 根据位置判断线路y=SLINE_1 为一线(lane=0)y=SLINE_2 为二线(lane=1)
const lane = pos.y === 130 ? 0 : 1; const lane = y === MonStart.SLINE_1 ? 0 : 1;
// 递增全局生成顺序 - 🔥 添加溢出保护 // 递增全局生成顺序 - 🔥 添加溢出保护
this.globalSpawnOrder = (this.globalSpawnOrder + 1) % 999; // 防止无限增长在999处循环重置 this.globalSpawnOrder = (this.globalSpawnOrder + 1) % 999; // 防止无限增长在999处循环重置