import { _decorator, resources, Sprite, SpriteAtlas } 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 { SkillSet } from "../common/config/SkillSet"; import { BoxSet } from "../common/config/BoxSet"; import { smc } from "../common/SingletonModuleComp"; const { ccclass, property } = _decorator; /** 视图层对象 */ @ccclass('MSkillComp') @ecs.register('MSkillComp', false) export class MSkillComp extends CCComp { s_uuid: number = 0; group: number = 0; lv:number = 0; skill_on:boolean = false; /** 视图层逻辑代码分离演示 */ start() { console.log("MSkillComp start s_uuid:",this.s_uuid,this.group); } init(){ console.log("MSkillComp init s_uuid:",this.s_uuid,this.group); if(SkillSet[this.s_uuid]==undefined){this.skill_on=false; return} this.s_uuid=smc.mission.mskill smc.vmdata.mission.exp_max=SkillSet[this.s_uuid].exp if(this.group == BoxSet.MONSTER){ this.s_uuid=smc.mission.mmskill smc.vmdata.mission.mexp_max=SkillSet[this.s_uuid].exp } var icon_path = "game/skills/skill_icon" resources.load(icon_path, SpriteAtlas, (err: any, atlas) => { const sprite = this.node.getChildByName("icon").getComponent(Sprite); sprite.spriteFrame = atlas.getSpriteFrame(SkillSet[this.s_uuid].path); }); this.skill_on=true } protected update(dt: number): void { if(!this.skill_on) return this.check_exp() } check_exp(){ switch(this.group){ case BoxSet.HERO: if(smc.vmdata.mission.exp >= SkillSet[this.s_uuid].exp){ console.log("hero MSkillComp check_exp s_uuid:",this.s_uuid,this.group); smc.vmdata.mission.exp-=SkillSet[this.s_uuid].exp this.lvup() } break; case BoxSet.MONSTER: if(smc.vmdata.mission.mexp >= SkillSet[this.s_uuid].exp){ console.log("monster MSkillComp check_exp s_uuid:",this.s_uuid,this.group); smc.vmdata.mission.mexp-=SkillSet[this.s_uuid].exp this.lvup() } } } lvup(){ console.log("MSkillComp lvup s_uuid:",this.s_uuid,this.group); } /** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */ reset() { this.node.destroy(); } }