refactor(skill): 重构技能系统以支持对象池复用

将技能节点管理改为使用对象池模式,提高性能
添加技能节点复用时的初始化逻辑
统一技能组件获取和重置方式
更新英雄配置中的默认技能
This commit is contained in:
walkpan
2026-01-02 23:37:20 +08:00
parent 81f55a796d
commit 557e43ed29
3 changed files with 60 additions and 10 deletions

View File

@@ -30,21 +30,31 @@ export class SkillView extends CCComp {
private maxAttackFrames: number = 1; // 最大攻击帧数,可配置
// 已命中目标追踪,防止重复伤害
start() {
this.init();
}
init() {
this.SConf = SkillSet[this.s_uuid]
this.sData=this.ent.get(SDataCom)
this.anim=this.node.getComponent(Animation)
this.sData = this.ent.get(SDataCom)
this.anim = this.node.getComponent(Animation)
this.node.active = true;
this.collider = this.getComponent(Collider2D);
if(this.collider) {
this.collider.group = this.group;
this.collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
this.collider.enabled = true; // 确保复用时开启
}
if(this.node.getComponent(Animation)){
let anim = this.node.getComponent(Animation);
//console.log("[SkillCom]:has anim",anim)
anim.on(Animation.EventType.FINISHED, this.onAnimationFinished, this);
// 对象池复用时,需要手动播放默认动画(因为 Play On Load 只在首次生效)
if (anim.defaultClip) {
anim.play(anim.defaultClip.name);
}
}
this.attackFrameCount = 0; // 重置攻击帧计数
}
onBeginContact (seCol: Collider2D, oCol: Collider2D) {
// 安全获取双方信息用于日志