57 lines
1.9 KiB
TypeScript
57 lines
1.9 KiB
TypeScript
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 { ItemComp } from "./ItemComp";
|
|
import { Items } from "../common/config/Items";
|
|
|
|
/** Item 模块 */
|
|
@ecs.register(`Item`)
|
|
export class Item extends ecs.Entity {
|
|
|
|
protected init() {
|
|
// this.addComponents<ecs.Comp>();
|
|
}
|
|
load(uuid:number=1001,num:number=0,praent:any=null) {
|
|
var path = "game/gui/item";
|
|
var prefab: Prefab = oops.res.get(path, Prefab)!;
|
|
var node = instantiate(prefab);
|
|
node.getChildByName("num").getComponent(Label).string = num.toString();
|
|
if(num==0){
|
|
node.getChildByName("num").getComponent(Label).string ="";
|
|
}
|
|
|
|
let url = "gui/items";
|
|
let pathName= Items[uuid].path;
|
|
switch(Items[uuid].lv){
|
|
case 1:
|
|
node.getChildByName("lv1").active = true;
|
|
break;
|
|
case 2:
|
|
node.getChildByName("lv2").active = true;
|
|
break;
|
|
case 3:
|
|
node.getChildByName("lv3").active = true;
|
|
break;
|
|
case 4:
|
|
node.getChildByName("lv4").active = true;
|
|
break;
|
|
}
|
|
resources.load(url, SpriteAtlas, (err: any, atlas) => {
|
|
const sprite = node.getChildByName("icon").getComponent(Sprite);
|
|
sprite.spriteFrame = atlas.getSpriteFrame(pathName);
|
|
});
|
|
node.parent = praent
|
|
let iv = node.getComponent(ItemComp)!;
|
|
iv.i_uuid = uuid
|
|
iv.num=num
|
|
this.add(iv)
|
|
}
|
|
/** 模块资源释放 */
|
|
destroy() {
|
|
|
|
super.destroy();
|
|
}
|
|
}
|
|
|
|
/** Item 模块业务逻辑系统组件,如无业务逻辑处理可删除此对象 */
|