import { EventTouch, Label, Node,Sprite,SpriteAtlas,_decorator, resources } 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 { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops"; import { UIID } from "../common/config/GameUIConfig"; import { Items } from "../common/config/Items"; const { ccclass, property } = _decorator; /** 视图层对象 */ @ccclass('ItemInfoComp') @ecs.register('ItemInfo', false) export class ItemInfoComp extends CCComp { onAdded(args: any) { this.node.getChildByName("name").getComponent(Label).string=args.name this.node.getChildByName("info").getComponent(Label).string=args.info let url = "gui/items"; let pathName= args.path; this.node.getChildByName("lv1").active = false; this.node.getChildByName("lv2").active = false; this.node.getChildByName("lv3").active = false; this.node.getChildByName("lv4").active = false; switch(Items[args.uuid].lv){ case 1: this.node.getChildByName("lv1").active = true; break; case 2: this.node.getChildByName("lv2").active = true; break; case 3: this.node.getChildByName("lv3").active = true; break; case 4: this.node.getChildByName("lv4").active = true; break; } resources.load(url, SpriteAtlas, (err: any, atlas) => { const sprite = this.node.getChildByName("icon").getComponent(Sprite); sprite.spriteFrame = atlas.getSpriteFrame(pathName); }); } private onTouchEnd(event: EventTouch) { switch (event.target.name) { case "btn": this.reset(); break; } event.propagationStopped = true; } reset() { oops.gui.remove(UIID.ItemInfo, false); // // 注:模拟二次删除清理缓存 // setTimeout(() => { // oops.gui.remove(UIID.ItemInfo); // }, 100); } protected onDestroy(): void { console.log("释放角色信息界面"); } }