From 9fcb6d31215634d13ecb8d300e57222f7fc7267e Mon Sep 17 00:00:00 2001 From: walkpan Date: Mon, 3 Nov 2025 13:36:33 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=B8=B2=E6=9F=93):=20=E9=87=8D=E6=9E=84?= =?UTF-8?q?=E6=B8=B2=E6=9F=93=E5=B1=82=E7=BA=A7=E7=AE=A1=E7=90=86=E5=B9=B6?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0BOSS=E5=B1=82=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 移除动态渲染层级更新逻辑,改为在实体加载时设置固定层级 - 在Hero和Monster的load方法中设置初始siblingIndex - 添加BOSS枚举值到IndexSet - 为Monster添加溢出保护,防止层级索引过大 - 删除墓地位置判断等不再需要的逻辑 --- assets/script/game/common/config/GameSet.ts | 3 +- assets/script/game/hero/Hero.ts | 7 ++- assets/script/game/hero/HeroMove.ts | 6 +- assets/script/game/hero/Mon.ts | 8 ++- assets/script/game/hero/MonMove.ts | 63 +-------------------- assets/script/game/map/MissionMonComp.ts | 4 +- 6 files changed, 20 insertions(+), 71 deletions(-) diff --git a/assets/script/game/common/config/GameSet.ts b/assets/script/game/common/config/GameSet.ts index 7a66105f..249cda6c 100644 --- a/assets/script/game/common/config/GameSet.ts +++ b/assets/script/game/common/config/GameSet.ts @@ -140,7 +140,8 @@ export enum IndexSet { MON2 = 3000, /** 每个怪物的层级增量,确保后生成的在前面 */ MON_INCREMENT = 1, - SLILL=4000 + SLILL=4000, + BOSS=2100, } export const TooltipTypes = { life:1, diff --git a/assets/script/game/hero/Hero.ts b/assets/script/game/hero/Hero.ts index b227adf6..6e144ca2 100644 --- a/assets/script/game/hero/Hero.ts +++ b/assets/script/game/hero/Hero.ts @@ -4,7 +4,7 @@ import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ec import { smc } from "../common/SingletonModuleComp"; import { HeroAttrsComp } from "./HeroAttrsComp"; import { HeroViewComp } from "./HeroViewComp"; -import { BoxSet, FacSet } from "../common/config/GameSet"; +import { BoxSet, FacSet, IndexSet } from "../common/config/GameSet"; import { HeroInfo, HeroPos, HType } from "../common/config/heroSet"; import { GameEvent } from "../common/config/GameEvent"; import { SkillSet } from "../common/config/SkillSet"; @@ -50,6 +50,11 @@ export class Hero extends ecs.Entity { const collider = node.getComponent(BoxCollider2D); if (collider) collider.enabled = false; // 先禁用 node.setPosition(pos) + + // 🔥 设置初始 SiblingIndex - 英雄基础层级 + 位置偏移 + const initialSiblingIndex = IndexSet.HERO; + node.setSiblingIndex(initialSiblingIndex); + // console.log("hero load",pos) var hv = node.getComponent(HeroViewComp)!; const model = this.get(HeroAttrsComp); diff --git a/assets/script/game/hero/HeroMove.ts b/assets/script/game/hero/HeroMove.ts index 9a071588..c1fdb56f 100644 --- a/assets/script/game/hero/HeroMove.ts +++ b/assets/script/game/hero/HeroMove.ts @@ -56,11 +56,7 @@ export class HeroMoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpd return; } - // 新增墓地位置判断,如果已经在墓地则不再移动 - if (view.node.position.x === -1000 || view.node.position.x === 1000) { - view.status_change("idle"); - return; - } + // 英雄阵营特殊逻辑:根据职业区分行为 const hasEnemies = this.checkEnemiesExist(e); diff --git a/assets/script/game/hero/Mon.ts b/assets/script/game/hero/Mon.ts index 82396854..6c15dce0 100644 --- a/assets/script/game/hero/Mon.ts +++ b/assets/script/game/hero/Mon.ts @@ -2,7 +2,7 @@ import { instantiate, Node, Prefab, Vec3 ,v3,resources,SpriteFrame,Sprite,Sprite import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops"; import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS"; import { smc } from "../common/SingletonModuleComp"; -import { BoxSet, FacSet } from "../common/config/GameSet"; +import { BoxSet, FacSet, IndexSet } from "../common/config/GameSet"; import { HeroInfo } from "../common/config/heroSet"; import { HeroAttrsComp } from "./HeroAttrsComp"; import { BuffConf, SkillSet } from "../common/config/SkillSet"; @@ -47,6 +47,12 @@ export class Monster extends ecs.Entity { if (collider) collider.enabled = false; // 先禁用 // 延迟一帧启用碰撞体 node.setPosition(pos) + // 🔥 设置初始 SiblingIndex - 防止溢出 + const baseLane = lane === 0 ? IndexSet.MON1 : IndexSet.MON2; + // 使用模运算防止索引溢出,确保在安全范围内循环 + const safeSpawnOrder = spawnOrder % 999; // 限制在999以内,避免溢出到其他层级 + const initialSiblingIndex = baseLane + safeSpawnOrder; + node.setSiblingIndex(initialSiblingIndex); var view = node.getComponent(HeroViewComp)!; const model = this.get(HeroAttrsComp); diff --git a/assets/script/game/hero/MonMove.ts b/assets/script/game/hero/MonMove.ts index e0155456..281e3c94 100644 --- a/assets/script/game/hero/MonMove.ts +++ b/assets/script/game/hero/MonMove.ts @@ -49,8 +49,7 @@ export class MonMoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpda const shouldStop = this.checkEnemiesInFace(e); model.is_atking = this.checkEnemiesInRange(e, model.Attrs[Attrs.DIS]); - // 更新渲染层级 - this.updateRenderOrder(e); + // 🔥 移除渲染层级更新:各线路固定,后召唤的天然层级更高,无需动态调整 if (!shouldStop) { if (model.is_stop || model.is_dead || model.isStun() || model.isFrost()) { @@ -58,11 +57,7 @@ export class MonMoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpda return; } - // 新增墓地位置判断,如果已经在墓地则不再移动 - if (view.node.position.x === -1000 || view.node.position.x === 1000) { - view.status_change("idle"); - return; - } + // 怪物简单移动逻辑:向目标方向移动 const delta = (model.Attrs[Attrs.SPEED]/3) * this.dt * move.direction; @@ -137,58 +132,4 @@ export class MonMoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpda }); return found; } - - /** 更新渲染层级 */ - private updateRenderOrder(entity: ecs.Entity) { - // 直接调用全局更新方法,避免重复计算 - this.updateAllUnitsRenderOrder(); - } - - /** 更新所有单位的渲染层级 */ - private updateAllUnitsRenderOrder() { - // 获取所有单位 - const allUnits = ecs.query(ecs.allOf(HeroAttrsComp, HeroViewComp)); - - // 创建单位数组,包含层级信息 - const unitsWithOrder: Array<{ - entity: ecs.Entity, - view: HeroViewComp, - order: number - }> = []; - - allUnits.forEach(e => { - const model = e.get(HeroAttrsComp); - const view = e.get(HeroViewComp); - - if (!view || !view.node || !model) return; - - let order = 0; - - if (model.fac === FacSet.HERO) { - // 英雄层级:基础层级 + y轴位置影响 - order = IndexSet.HERO + Math.floor(view.node.position.y); - } else if (model.fac === FacSet.MON) { - const move = e.get(MonMoveComp); - if (move) { - // 怪物层级:基于线路和生成顺序 - const baseLane = move.lane === 0 ? IndexSet.MON1 : IndexSet.MON2; - order = baseLane + (move.spawnOrder * IndexSet.MON_INCREMENT); - } - } - - unitsWithOrder.push({ - entity: e, - view: view, - order: order - }); - }); - - // 按层级排序:order值小的在后面(siblingIndex小),order值大的在前面(siblingIndex大) - unitsWithOrder.sort((a, b) => a.order - b.order); - - // 设置 siblingIndex - unitsWithOrder.forEach((unit, index) => { - unit.view.node.setSiblingIndex(index); - }); - } } \ No newline at end of file diff --git a/assets/script/game/map/MissionMonComp.ts b/assets/script/game/map/MissionMonComp.ts index 0085f9fc..4cfc8b1d 100644 --- a/assets/script/game/map/MissionMonComp.ts +++ b/assets/script/game/map/MissionMonComp.ts @@ -193,8 +193,8 @@ export class MissionMonCompComp extends CCComp { // 根据位置判断线路:y=110为一线(lane=0),y=80为二线(lane=1) const lane = pos.y === 110 ? 0 : 1; - // 递增全局生成顺序 - this.globalSpawnOrder++; + // 递增全局生成顺序 - 🔥 添加溢出保护 + this.globalSpawnOrder = (this.globalSpawnOrder + 1) % 999; // 防止无限增长,在999处循环重置 // 生成怪物,传递线路和生成顺序 mon.load(pos, scale, uuid, lv, monType, buffs, false, lane, this.globalSpawnOrder);