英雄上阵选择 基本完成
This commit is contained in:
44
assets/script/game/hero/HeroSelect.ts
Normal file
44
assets/script/game/hero/HeroSelect.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
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 { HeroSelectComp } from "./HeroSelectComp";
|
||||
import { smc } from "../common/SingletonModuleComp";
|
||||
import { HeroInfo } from "../common/config/heroSet";
|
||||
|
||||
/** HeroSelect 模块 */
|
||||
@ecs.register(`HeroSelect`)
|
||||
export class HeroSelect extends ecs.Entity {
|
||||
|
||||
protected init() {
|
||||
// this.addComponents<ecs.Comp>();
|
||||
}
|
||||
load(uuid:number=101,parent:any) {
|
||||
// var path = "game/monster/"+prefab_path;
|
||||
var path = "game/gui/hero_set";
|
||||
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(HeroSelectComp)!;
|
||||
console.log(hcc)
|
||||
hcc.h_uuid = uuid;
|
||||
this.add(hcc);
|
||||
}
|
||||
/** 模块资源释放 */
|
||||
destroy() {
|
||||
// 注: 自定义释放逻辑,视图层实现 ecs.IComp 接口的 ecs 组件需要手动释放
|
||||
super.destroy();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user