import { Prefab,instantiate,Vec3,v3 ,SpriteAtlas,resources,Sprite,Node} from "cc"; import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS"; import { CSkillComp } from "./CSkillComp"; import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops"; import { smc } from "../common/SingletonModuleComp"; import { SkillSet } from "../common/config/CardSet"; /** CSkill 模块 */ @ecs.register(`CSkill`) export class CSkill extends ecs.Entity { CSkillView!: CSkillComp; /** 实始添加的数据层组件 */ protected init() { } /** 模块资源释放 */ destroy() { this.remove(CSkillComp); // 注: 自定义释放逻辑,视图层实现 ecs.IComp 接口的 ecs 组件需要手动释放 super.destroy(); } start(){ } /** 加载角色 */ load(pos: Vec3 = Vec3.ZERO,scale:number = 1,uuid:number=1001) { // var path = "game/monster/"+prefab_path; console.log("load skill",this) var path = "game/heros/skill"; var prefab: Prefab = oops.res.get(path, Prefab)!; var node = instantiate(prefab); var scene = smc.map.MapView.scene; node.parent = scene.entityLayer!.node!; node.getChildByName("skill").setScale(node.getChildByName("skill").scale.x*scale, node.getChildByName("skill").scale.y, node.getChildByName("skill").scale.z); // let cskills = ecs.query(ecs.allOf(CSkillComp)) for (let index = 1; index <= 8; index++) { if(smc.player_buffs[index].eid == 0){ pos.x=smc.player_buffs[index].x pos.y=smc.player_buffs[index].y smc.player_buffs[index].eid=this.eid break } } // console.log("load skill",pos,smc.player_buffs) node.setPosition(pos.x*scale,pos.y,pos.z) // console.log(node.getChildByName("avatar").getChildByName("TNode").getChildByName("bb").getComponent(Sprite)) const url = 'game/heros/skill'; resources.load(url, SpriteAtlas, (err: any, atlas) => { const sprite = node.getChildByName("skill").getComponent(Sprite); sprite.spriteFrame = atlas.getSpriteFrame(SkillSet[uuid].path); }); this.skill_init(uuid,node,pos) oops.message.dispatchEvent("cskill_load",this) } skill_init(uuid:number=1001,node:Node,pos:Vec3=v3(0,0,0)){ var mv = node.getComponent(CSkillComp) mv.scale = 1; this.add(mv); } } /** CSkill 模块业务逻辑系统组件,如无业务逻辑处理可删除此对象 */ export class EcsCSkillSystem extends ecs.System { constructor() { super(); // this.add(new ecs.ComblockSystem()); } }