import { mLogger } from "../common/Logger"; import { _decorator, Node, Prefab, instantiate } 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 { oops } from "db://oops-framework/core/Oops"; import { GameEvent } from "../common/config/GameEvent"; import { smc } from "../common/SingletonModuleComp"; const { ccclass, property } = _decorator; /** 视图层对象 */ @ccclass('MissSkillsComp') @ecs.register('MissSkillsComp', false) export class MissSkillsComp extends CCComp { private debugMode: boolean = true; @property({type: Prefab}) private skill_box: Prefab = null; onLoad() { oops.message.on(GameEvent.UseSkillCard, this.onUseSkillCard, this); this.node.parent=smc.map.MapView.scene.entityLayer!.node! } onDestroy() { oops.message.off(GameEvent.UseSkillCard, this.onUseSkillCard, this); } private onUseSkillCard(event: string, args: any) { const payload = args ?? event; const uuid = Number(payload?.uuid ?? 0); const card_lv = Math.max(1, Math.floor(Number(payload?.card_lv ?? 1))); if (!uuid) return; this.addSkill(uuid, card_lv); } start() { } addSkill(uuid: number, card_lv: number) { if (!this.skill_box) { mLogger.error(this.debugMode, "MissSkillsComp", "skill_box prefab not set"); return; } const node = instantiate(this.skill_box); node.parent = this.node; const comp = node.getComponent(SkillBoxComp) || node.addComponent(SkillBoxComp); comp.init(uuid, card_lv); } /** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */ reset() { this.node.destroy(); } }