背后载入
This commit is contained in:
63
assets/script/game/heros/Hero.ts
Normal file
63
assets/script/game/heros/Hero.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
|
||||
/*
|
||||
* @Author: dgflash
|
||||
* @Date: 2021-11-18 17:47:56
|
||||
* @LastEditors: dgflash
|
||||
* @LastEditTime: 2022-08-04 15:43:04
|
||||
*/
|
||||
import { instantiate, Node, Prefab, tween, Vec3,Label } 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 { HeroModelComp } from "./HeroModelComp";
|
||||
import { HeroSpine } from "./HeroSpine";
|
||||
import { HeroViewComp } from "./HeroViewComp";
|
||||
|
||||
/** 角色实体 */
|
||||
@ecs.register(`Hero`)
|
||||
export class Hero extends ecs.Entity {
|
||||
// 数据层
|
||||
HeroModel!: HeroModelComp;
|
||||
// 视图层
|
||||
HeroView!: HeroViewComp;
|
||||
|
||||
protected init() {
|
||||
this.addComponents<ecs.Comp>(
|
||||
HeroModelComp);
|
||||
}
|
||||
|
||||
destroy(): void {
|
||||
this.remove(HeroViewComp);
|
||||
super.destroy();
|
||||
}
|
||||
|
||||
/** 加载角色 */
|
||||
load(pos: Vec3 = Vec3.ZERO,profession:string = "war") {
|
||||
var path = "game/heros/"+profession;
|
||||
var prefab: Prefab = oops.res.get(path, Prefab)!;
|
||||
var node = instantiate(prefab);
|
||||
let label =node.getChildByName("top").getChildByName("lab_name")
|
||||
label.getComponent(Label)!.string = profession;
|
||||
var scene = smc.map.MapView.scene;
|
||||
node.parent = scene.entityLayer!.node!;
|
||||
var as = node.getComponent(HeroSpine);
|
||||
node.setPosition(pos)
|
||||
node.setScale(1, 1, 1);
|
||||
var mv = node.getComponent(HeroViewComp)!;
|
||||
this.add(mv);
|
||||
let speed = smc.heros[0].speed;
|
||||
tween(node).to(speed/60, { position: new Vec3(0, -60, 0) }, {
|
||||
onComplete: () => {
|
||||
// this.as.walk();
|
||||
}
|
||||
}).start();
|
||||
//移除全局列表
|
||||
smc.heros.splice(0,1)
|
||||
console.log(ecs.query(ecs.allOf(HeroViewComp))
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
1
assets/script/game/heros/Hero.ts.meta
Normal file
1
assets/script/game/heros/Hero.ts.meta
Normal file
@@ -0,0 +1 @@
|
||||
{"ver":"4.0.23","importer":"typescript","imported":true,"uuid":"984e9949-2b16-4e46-bb30-6ac00a2a838e","files":[],"subMetas":{},"userData":{}}
|
||||
27
assets/script/game/heros/HeroModelComp.ts
Normal file
27
assets/script/game/heros/HeroModelComp.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* @Author: dgflash
|
||||
* @Date: 2021-11-18 15:56:01
|
||||
* @LastEditors: dgflash
|
||||
* @LastEditTime: 2022-08-17 13:43:25
|
||||
*/
|
||||
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||
|
||||
/**
|
||||
* 角色属性数据
|
||||
*/
|
||||
@ecs.register('HeroModel')
|
||||
export class HeroModelComp extends ecs.Comp {
|
||||
/** 角色编号 */
|
||||
id: number = -1;
|
||||
|
||||
/** 角色名 */
|
||||
name: string = "Hero";
|
||||
|
||||
/** 动画名资源 */
|
||||
anim: string = "Hero";
|
||||
|
||||
reset() {
|
||||
this.id = -1;
|
||||
this.name = "";
|
||||
}
|
||||
}
|
||||
1
assets/script/game/heros/HeroModelComp.ts.meta
Normal file
1
assets/script/game/heros/HeroModelComp.ts.meta
Normal file
@@ -0,0 +1 @@
|
||||
{"ver":"4.0.23","importer":"typescript","imported":true,"uuid":"0ce59d56-a495-4b95-9405-a8a85d47a439","files":[],"subMetas":{},"userData":{}}
|
||||
@@ -5,7 +5,7 @@
|
||||
* @LastEditTime: 2022-08-17 12:36:18
|
||||
*/
|
||||
|
||||
import { Vec3, _decorator } from "cc";
|
||||
import { Vec3, _decorator ,tween} 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 { HeroSpine } from "./HeroSpine";
|
||||
@@ -23,6 +23,7 @@ export class HeroViewComp extends CCComp {
|
||||
/** 视图层逻辑代码分离演示 */
|
||||
onLoad() {
|
||||
this.as = this.getComponent(HeroSpine);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user