import { instantiate, Label, Prefab, resources, Sprite, SpriteAtlas } from "cc"; import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS"; import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops"; import { HeroCardComp } from "./HeroCardComp"; import { smc } from "../common/SingletonModuleComp"; import { HeroInfo } from "../common/config/heroSet"; /** HeroCard 模块 */ @ecs.register(`HeroCard`) export class HeroCard extends ecs.Entity { protected init() { // this.addComponents(); } load(uuid:number=101,parent:any) { // var path = "game/monster/"+prefab_path; var path = "game/gui/hero_card"; var icon_path = "game/heros/herois" var prefab: Prefab = oops.res.get(path, Prefab)!; var node = instantiate(prefab); let slv = node.getChildByName("slv"); node.parent = parent; node.getChildByName("name").getComponent(Label).string = HeroInfo[uuid].name resources.load(icon_path, SpriteAtlas, (err: any, atlas) => { const sprite = node.getChildByName("Mask").getChildByName("hero").getComponent(Sprite); sprite.spriteFrame = atlas.getSpriteFrame(HeroInfo[uuid].path); }); node.getChildByName("lv").getComponent(Label).string = smc.heros[uuid].lv.toString()+"级"; if(smc.heros[uuid].slv>=1) {slv.getChildByName("s1").active=true} else {slv.getChildByName("s1").active=false}; if(smc.heros[uuid].slv>=2) {slv.getChildByName("s2").active=true} else {slv.getChildByName("s2").active=false}; if(smc.heros[uuid].slv>=3) {slv.getChildByName("s3").active=true} else {slv.getChildByName("s3").active=false}; if(smc.heros[uuid].slv>=4) {slv.getChildByName("s4").active=true} else {slv.getChildByName("s4").active=false}; if(smc.heros[uuid].slv>=5) {slv.getChildByName("s5").active=true} else {slv.getChildByName("s5").active=false}; let hcc = node.getComponent(HeroCardComp)!; hcc.h_uuid = uuid; this.add(hcc); } /** 模块资源释放 */ destroy() { // 注: 自定义释放逻辑,视图层实现 ecs.IComp 接口的 ecs 组件需要手动释放 super.destroy(); } }