Files
pixelheros/assets/script/game/hero/HeroAnmComp.ts
pan 4263997124 fix(hero): 修复大招播放结束后未取消层级置顶的问题
1. 新增isCastingMax标记跟踪大招播放状态,在释放大招时设置该标记
2. 在动画播放结束回调中,当大招动画播放完成时清除置顶标记
3. 调整渲染排序逻辑,将大招播放中的英雄置于渲染层级最下方
4. 在角色死亡和重置时同步重置置顶标记
2026-09-01 16:41:26 +08:00

92 lines
3.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { _decorator, Animation, AnimationState, CCClass, Component, } from "cc";
import { HeroViewComp } from "./HeroViewComp";
import { FacSet } from "../common/config/GameSet";
import { FlashSprite } from "./hit-flash-white/scripts/FlashSprite";
const { ccclass, property } = _decorator;
@ccclass('HeroAnmComp')
export default class HeroAnmComp extends Component {
fsSprite: FlashSprite = null!;
private anmcon: any = null
private _hasStop = true;
private _atkIndex = 0;
private default_anim: string = 'idle'
anms: any[] = ["idle", "move", "atk0", "max0", "max1"]
onLoad() {
this.anmcon = this.node.getComponent(Animation)
this.fsSprite = this.node.getComponent(FlashSprite);
this.anmcon.on(Animation.EventType.FINISHED, this.onAnimationFinished, this);
}
onDestroy() {
if (this.anmcon) {
this.anmcon.off(Animation.EventType.FINISHED, this.onAnimationFinished, this);
}
}
/** 大招是否播放中(最高优先级,期间禁止一切动画切换) */
private get maxPlaying(): boolean {
return !!(this.anmcon.getState("max0")?.isPlaying || this.anmcon.getState("max1")?.isPlaying);
}
/** 普攻是否播放中(次优先级,仅可被大招打断) */
private get atkPlaying(): boolean {
return !!this.anmcon.getState("atk0")?.isPlaying;
}
/** buff 是否播放中(可被大招/普攻打断,但拦截 idle/move) */
private get buffPlaying(): boolean {
return !!this.anmcon.getState("buff")?.isPlaying;
}
stop() {
this._hasStop = true;
}
onAnimationFinished(type: Animation.EventType, state: AnimationState) {
if (state.name === "max0" || state.name === "max1") {
// 大招播放结束,清除 HeroViewComp 的置顶标记,恢复 MoveSystem 统一排序
const viewComp = this.node.getComponent(HeroViewComp) || this.node.getComponentInParent(HeroViewComp);
if (viewComp) {
viewComp.isCastingMax = false;
}
}
if (state.name != "idle" && state.name != "move") {
this.anmcon.play(this.default_anim)
}
}
atked() {
this.fsSprite.clickFlash();
}
move() {
if (this.maxPlaying || this.atkPlaying || this.buffPlaying) return
if (this.anmcon.getState("move").isPlaying) return
this.anmcon.play("move")
this.default_anim = 'move'
}
atk() {
if (this.maxPlaying) return
this.anmcon.play(`atk0`)
}
max() {
if (this.maxPlaying) return
this.anmcon.play("max0")
}
play(anm: string = "") {
if (anm === "") return
if (this.maxPlaying) return
this.anmcon.play(anm)
}
idle() {
if (this.maxPlaying || this.atkPlaying || this.buffPlaying) return
if (this.anmcon.getState("idle").isPlaying) return
this.anmcon.play("idle")
this.default_anim = 'idle'
}
buff() {
if (this.maxPlaying) return
this.anmcon.play("buff")
}
dead() {
}
}