fix: 修复Boss渲染层级错误,确保Boss始终显示在最前
Boss单位在渲染排序时未获得足够高的优先级,导致可能被其他单位遮挡。 现在为Boss单位添加专门的渲染优先级字段(bossPriority),并在排序时作为第一排序条件。 同时为Boss的spawnOrder添加偏移量,确保同优先级内Boss保持正确的生成顺序。
This commit is contained in:
@@ -47,7 +47,7 @@ export class MoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
|
||||
private renderSortElapsed = 0;
|
||||
private heroMoveMatcher: ecs.IMatcher | null = null;
|
||||
private heroViewMatcher: ecs.IMatcher | null = null;
|
||||
private readonly renderEntries: { node: Node; frontScore: number; spawnOrder: number; eid: number }[] = [];
|
||||
private readonly renderEntries: { node: Node; bossPriority: number; frontScore: number; spawnOrder: number; eid: number }[] = [];
|
||||
private renderEntryCount = 0;
|
||||
|
||||
private readonly facConfigs: Record<number, MoveFacConfig> = {
|
||||
@@ -431,10 +431,11 @@ export class MoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
|
||||
const entryIndex = this.renderEntryCount;
|
||||
let entry = this.renderEntries[entryIndex];
|
||||
if (!entry) {
|
||||
entry = { node: actorView.node, frontScore: 0, spawnOrder: 0, eid: 0 };
|
||||
entry = { node: actorView.node, bossPriority: 0, frontScore: 0, spawnOrder: 0, eid: 0 };
|
||||
this.renderEntries.push(entry);
|
||||
}
|
||||
entry.node = actorView.node;
|
||||
entry.bossPriority = attrs.is_boss ? 1 : 0;
|
||||
entry.frontScore = frontScore;
|
||||
entry.spawnOrder = actorMove.spawnOrder;
|
||||
entry.eid = e.eid;
|
||||
@@ -443,6 +444,7 @@ export class MoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
|
||||
this.renderEntries.length = this.renderEntryCount;
|
||||
|
||||
this.renderEntries.sort((a, b) => {
|
||||
if (a.bossPriority !== b.bossPriority) return a.bossPriority - b.bossPriority;
|
||||
if (a.frontScore !== b.frontScore) return a.frontScore - b.frontScore;
|
||||
if (a.spawnOrder !== b.spawnOrder) return a.spawnOrder - b.spawnOrder;
|
||||
return a.eid - b.eid;
|
||||
|
||||
@@ -9,12 +9,14 @@ import { GameEvent } from "../common/config/GameEvent";
|
||||
import {BoxSet } from "../common/config/GameSet";
|
||||
import { BossList, BossSpawnCd, MonList, MonType, SpawnBaseCd, SpawnMinCd, SpawnPowerBias, SpawnStageReduce, StageBossGrow, StageDuration, StageGrow, UpType } from "./RogueConfig";
|
||||
import { HeroAttrsComp } from "../hero/HeroAttrsComp";
|
||||
import { MoveComp } from "../hero/MoveComp";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
/** 视图层对象 */
|
||||
@ccclass('MissionMonCompComp')
|
||||
@ecs.register('MissionMonComp', false)
|
||||
export class MissionMonCompComp extends CCComp {
|
||||
private static readonly BOSS_RENDER_PRIORITY = 1000000;
|
||||
@property({ tooltip: "是否启用调试日志" })
|
||||
private debugMode: boolean = false;
|
||||
|
||||
@@ -201,8 +203,13 @@ export class MissionMonCompComp extends CCComp {
|
||||
// 递增全局生成顺序,做溢出保护
|
||||
this.globalSpawnOrder = (this.globalSpawnOrder + 1) % 999;
|
||||
|
||||
// 先用原始配置创建怪物,再覆盖成长后属性
|
||||
mon.load(pos, scale, uuid, isBoss);
|
||||
const move = mon.get(MoveComp);
|
||||
if (move) {
|
||||
move.spawnOrder = isBoss
|
||||
? MissionMonCompComp.BOSS_RENDER_PRIORITY + this.globalSpawnOrder
|
||||
: this.globalSpawnOrder;
|
||||
}
|
||||
const model = mon.get(HeroAttrsComp);
|
||||
const base = HeroInfo[uuid];
|
||||
if (!model || !base) return;
|
||||
|
||||
Reference in New Issue
Block a user