refactor(skill): 重构技能盒子管理为ECS实体架构

新增SBox ECS实体,统一管理技能盒子的创建、挂载与销毁
重构MissSkillsComp,改用SBox实体替代直接实例化技能节点
更新SkillBoxComp,新增实体引用以通过ECS生命周期销毁节点
临时调整SCastSystem的索敌范围为全屏级,方便测试
This commit is contained in:
pan
2026-06-04 14:41:27 +08:00
parent c5d521136d
commit efe6cc0dd7
5 changed files with 95 additions and 17 deletions

View File

@@ -25,6 +25,7 @@ import { _decorator, Node, Prefab, instantiate, Vec3 } from "cc";
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
import { SkillBoxComp } from "./SkillBoxComp";
import { SBox } from "./SBox";
import { oops } from "db://oops-framework/core/Oops";
import { GameEvent } from "../common/config/GameEvent";
import { smc } from "../common/SingletonModuleComp";
@@ -164,9 +165,6 @@ export class MissSkillsComp extends CCComp {
* @param card_lv 技能卡等级
*/
addSkill(uuid: number, card_lv: number) {
// 技能节点的父容器
var parent = smc.map.MapView.scene.entityLayer!.node!.getChildByName("SKILL")!;
if (!this.skill_box) {
mLogger.error(this.debugMode, "MissSkillsComp", "skill_box prefab not set");
return;
@@ -179,17 +177,13 @@ export class MissSkillsComp extends CCComp {
return;
}
// 实例化并放入槽位
const node = instantiate(this.skill_box);
node.parent = parent;
node.setPosition(new Vec3(this.slots[emptyIndex].x, this.slots[emptyIndex].y, 0));
// 使用 ECS 实体创建技能节点
let sbox = ecs.getEntity<SBox>(SBox);
let pos = new Vec3(this.slots[emptyIndex].x, this.slots[emptyIndex].y, 0);
let node = sbox.load(uuid, card_lv, pos, this.skill_box);
this.slots[emptyIndex].used = true;
this.slots[emptyIndex].node = node;
// 初始化技能效果组件
const comp = node.getComponent(SkillBoxComp) || node.addComponent(SkillBoxComp);
comp.init(uuid, card_lv);
}
/** ECS 组件移除时销毁节点 */