82 lines
2.6 KiB
TypeScript
82 lines
2.6 KiB
TypeScript
|
|
/*
|
|
* @Author: dgflash
|
|
* @Date: 2021-11-18 17:47:56
|
|
* @LastEditors: dgflash
|
|
* @LastEditTime: 2022-08-04 15:43:04
|
|
*/
|
|
import { instantiate, Node, Prefab, Vec3 ,tween, v3,SpriteAtlas,Label,resources,SpriteFrame,Sprite} from "cc";
|
|
import { UICallbacks } from "../../../../extensions/oops-plugin-framework/assets/core/gui/layer/Defines";
|
|
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
|
|
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
|
import { UIID } from "../common/config/GameUIConfig";
|
|
import { smc } from "../common/SingletonModuleComp";
|
|
import{HeroCardViewComp} from "./HeroCardViewComp";
|
|
import { CardSet ,SkillSet} from "../common/config/CardSet";
|
|
/** 角色实体 */
|
|
@ecs.register(`HeroCard`)
|
|
export class HeroCard extends ecs.Entity {
|
|
// 数据层
|
|
|
|
// 视图层
|
|
|
|
|
|
protected init() {
|
|
|
|
}
|
|
|
|
destroy(): void {
|
|
this.remove(HeroCardViewComp);
|
|
super.destroy();
|
|
}
|
|
|
|
/** 加载角色 */
|
|
load(pos: Vec3 = Vec3.ZERO,uuid:number=1001,parent:Node,type:number=1) {
|
|
let path: string;
|
|
let url: string;
|
|
let pathName: string;
|
|
let name: string;
|
|
let level: number;
|
|
|
|
switch (type) {
|
|
case 1:
|
|
path = "game/heros/hero_card";
|
|
url = "game/heros/heros";
|
|
({ path: pathName, name, level } = smc.heros[uuid]);
|
|
break;
|
|
case 2:
|
|
path = "game/heros/skill_card";
|
|
url = "game/heros/skill";
|
|
({ path: pathName, name, level } = SkillSet[uuid]);
|
|
break;
|
|
case 3:
|
|
default:
|
|
path = "game/heros/hero_card";
|
|
url = "game/heros/heros";
|
|
({ path: pathName, name, level } = smc.heros[uuid]);
|
|
}
|
|
|
|
|
|
var prefab: Prefab = oops.res.get(path, Prefab)!;
|
|
var node = instantiate(prefab);
|
|
node.parent = parent;
|
|
// node.getChildByName("avatar").setScale(node.getChildByName("avatar").scale.x*camp, node.getChildByName("avatar").scale.y, node.getChildByName("avatar").scale.z);
|
|
node.setPosition(pos)
|
|
|
|
|
|
resources.load(url, SpriteAtlas, (err: any, atlas) => {
|
|
const sprite = node.getChildByName("hero").getComponent(Sprite);
|
|
sprite.spriteFrame = atlas.getSpriteFrame(pathName);
|
|
});
|
|
|
|
var hcv = node.getComponent(HeroCardViewComp)!;
|
|
hcv.card_name=name
|
|
hcv.card_uid=uuid
|
|
hcv.card_type=type
|
|
hcv.card_level=level
|
|
this.add(hcv);
|
|
|
|
}
|
|
|
|
}
|