dd
This commit is contained in:
@@ -23,8 +23,10 @@ export class Main extends Root {
|
|||||||
|
|
||||||
protected async run() {
|
protected async run() {
|
||||||
smc.initialize = ecs.getEntity<Initialize>(Initialize);
|
smc.initialize = ecs.getEntity<Initialize>(Initialize);
|
||||||
|
smc.monsters = ['war','magic','heath']
|
||||||
|
smc.heros = ['war','magic','heath']
|
||||||
|
console.log("Game start");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected initGui() {
|
protected initGui() {
|
||||||
oops.gui.init(UIConfigData);
|
oops.gui.init(UIConfigData);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,10 @@ export class SingletonModuleComp extends ecs.Comp {
|
|||||||
own: Role = null;
|
own: Role = null;
|
||||||
/** 游戏数据 */
|
/** 游戏数据 */
|
||||||
data:data = null!;
|
data:data = null!;
|
||||||
|
/**怪物数据 数组 */
|
||||||
|
monsters = []
|
||||||
|
/**heros 数据 */
|
||||||
|
heros = [];
|
||||||
|
|
||||||
reset() { }
|
reset() { }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ export class Initialize extends ecs.Entity {
|
|||||||
this.data=ecs.getEntity<data>(data);
|
this.data=ecs.getEntity<data>(data);
|
||||||
this.data.dataModel.vmAdd();
|
this.data.dataModel.vmAdd();
|
||||||
var queue: AsyncQueue = new AsyncQueue();
|
var queue: AsyncQueue = new AsyncQueue();
|
||||||
// 加载自定义资源
|
// 加载自定义资
|
||||||
this.loadCustom(queue);
|
this.loadCustom(queue);
|
||||||
// 加载多语言包
|
// 加载多语言包
|
||||||
this.loadLanguage(queue);
|
this.loadLanguage(queue);
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { smc } from "../../common/SingletonModuleComp";
|
|||||||
import { Role } from "../../role/Role";
|
import { Role } from "../../role/Role";
|
||||||
// import MapRoadUtils from "./map/road/MapRoadUtils";
|
// import MapRoadUtils from "./map/road/MapRoadUtils";
|
||||||
import { MapViewScene } from "./MapViewScene";
|
import { MapViewScene } from "./MapViewScene";
|
||||||
|
import { Timer } from "../../../../../extensions/oops-plugin-framework/assets/core/common/timer/Timer";
|
||||||
const { ccclass, property } = _decorator;
|
const { ccclass, property } = _decorator;
|
||||||
|
|
||||||
@ccclass('MapViewComp')
|
@ccclass('MapViewComp')
|
||||||
@@ -20,7 +20,7 @@ export class MapViewComp extends CCComp {
|
|||||||
current_map: any;
|
current_map: any;
|
||||||
/** 转场碰撞点对象集合 */
|
/** 转场碰撞点对象集合 */
|
||||||
|
|
||||||
|
private timer: Timer = new Timer(2);
|
||||||
|
|
||||||
reset(): void {
|
reset(): void {
|
||||||
|
|
||||||
@@ -28,11 +28,16 @@ export class MapViewComp extends CCComp {
|
|||||||
|
|
||||||
start() {
|
start() {
|
||||||
this.scene = this.getComponent(MapViewScene);
|
this.scene = this.getComponent(MapViewScene);
|
||||||
this.addHero();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 转场 */
|
/** 转场 */
|
||||||
|
protected update(dt: number): void {
|
||||||
|
if (this.timer.update(dt)) {
|
||||||
|
console.log('每2秒触发一次');
|
||||||
|
this.addHero();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private mapLoaded() {
|
private mapLoaded() {
|
||||||
|
|
||||||
@@ -40,33 +45,60 @@ export class MapViewComp extends CCComp {
|
|||||||
|
|
||||||
/** 添加玩家 */
|
/** 添加玩家 */
|
||||||
private addHero(pos?: Vec3) {
|
private addHero(pos?: Vec3) {
|
||||||
if (pos == null) {
|
|
||||||
this.scene.node.active = true
|
this.scene.node.active = true
|
||||||
smc.own = ecs.getEntity<Role>(Role);
|
// smc.monsters = ['war','magic','heath']
|
||||||
smc.own.load(this.aStarToVec3("-360,-60"), false);
|
// smc.heros = ['war','magic','heath']
|
||||||
|
if (smc.heros.length>0){
|
||||||
|
let hero = ecs.getEntity<Role>(Role);
|
||||||
|
let x = this.getRandomInt(-300, 0)
|
||||||
|
hero.load(this.aStarToVec3(x+',60'), false, "magic");
|
||||||
|
}
|
||||||
|
if (smc.monsters.length>0){
|
||||||
|
let monster = ecs.getEntity<Role>(Role);
|
||||||
|
let x = this.getRandomInt(0, 300)
|
||||||
|
monster.load(this.aStarToVec3(x+'60'), true, "magic");
|
||||||
|
}
|
||||||
|
|
||||||
// smc.own.loadJoystick();
|
// smc.own.loadJoystick();
|
||||||
|
// smc.heros.forEach(element => {
|
||||||
// 测试玩家
|
// var heros$i = ecs.getEntity<Role>(Role);
|
||||||
var test = ecs.getEntity<Role>(Role);
|
// let i =1
|
||||||
test.load(this.aStarToVec3("-270,-60"), false);
|
// switch (element) {
|
||||||
var test1 = ecs.getEntity<Role>(Role);
|
// case "war":
|
||||||
test1.load(this.aStarToVec3("-180,-60"), false);
|
// heros$i.load(this.aStarToVec3("-30,-60"), false);
|
||||||
var test2 = ecs.getEntity<Role>(Role);
|
// break;
|
||||||
test2.load(this.aStarToVec3("-90,-60"), false);
|
// case "magic":
|
||||||
|
// heros$i.load(this.aStarToVec3("-140,-60"), false);
|
||||||
// var test3 = ecs.getEntity<Role>(Role);
|
// break;
|
||||||
// test3.load(this.aStarToVec3("0,-60"), false);
|
// case "heath":
|
||||||
var test4 = ecs.getEntity<Role>(Role);
|
// heros$i.load(this.aStarToVec3("-230,-60"), false)
|
||||||
test4.load(this.aStarToVec3("90,-60"), true,"monster");
|
// }
|
||||||
var test5 = ecs.getEntity<Role>(Role);
|
// i=i+1
|
||||||
test5.load(this.aStarToVec3("180,-60"), true,"magic");
|
// });
|
||||||
var test6 = ecs.getEntity<Role>(Role);
|
// let x = 1
|
||||||
test6.load(this.aStarToVec3("270,-60"), true,"heath");
|
// smc.monsters.forEach(element => {
|
||||||
var test7 = ecs.getEntity<Role>(Role);
|
// var monsters$x = ecs.getEntity<Role>(Role);
|
||||||
test7.load(this.aStarToVec3("360,-60"), true);
|
// switch (element) {
|
||||||
}
|
// case "war":
|
||||||
|
// monsters$x.load(this.aStarToVec3("30,-60"), true);
|
||||||
|
// break;
|
||||||
|
// case "magic":
|
||||||
|
// monsters$x.load(this.aStarToVec3("140,-60"), true);
|
||||||
|
// break;
|
||||||
|
// case "heath":
|
||||||
|
// monsters$x.load(this.aStarToVec3("230,-60"), true)
|
||||||
|
// }
|
||||||
|
// x=x+1
|
||||||
|
// });
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
private getRandomInt(min: number, max: number): number {
|
||||||
|
min = Math.ceil(min);
|
||||||
|
max = Math.floor(max);
|
||||||
|
return Math.floor(Math.random() * (max - min + 1)) + min;
|
||||||
}
|
}
|
||||||
|
|
||||||
private aStarToVec3(str: string) {
|
private aStarToVec3(str: string) {
|
||||||
let array = str.split(",");
|
let array = str.split(",");
|
||||||
let x = parseInt(array[0]);
|
let x = parseInt(array[0]);
|
||||||
|
|||||||
@@ -34,18 +34,21 @@ export class Role extends ecs.Entity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** 加载角色 */
|
/** 加载角色 */
|
||||||
load(pos: Vec3 = Vec3.ZERO, isMonster: boolean = false,skin:string = "war") {
|
load(pos: Vec3 = Vec3.ZERO, isMonster: boolean = false,type:string = "monster",anim:string = "idle") {
|
||||||
|
console.log("load role type",type);
|
||||||
var path = "game/player/player";
|
var path = "game/player/player";
|
||||||
|
|
||||||
var prefab: Prefab = oops.res.get(path, Prefab)!;
|
var prefab: Prefab = oops.res.get(path, Prefab)!;
|
||||||
var node = instantiate(prefab);
|
var node = instantiate(prefab);
|
||||||
var scene = smc.map.MapView.scene;
|
var scene = smc.map.MapView.scene;
|
||||||
node.parent = scene.entityLayer!.node!;
|
node.parent = scene.entityLayer!.node!;
|
||||||
|
var as = node.getComponent(RoleSpine);
|
||||||
|
as.play(anim, true);
|
||||||
node.setPosition(pos)
|
node.setPosition(pos)
|
||||||
|
|
||||||
var mv = node.getComponent(RoleViewComp)!;
|
var mv = node.getComponent(RoleViewComp)!;
|
||||||
this.add(mv);
|
this.add(mv);
|
||||||
var as = node.getComponent(RoleSpine);
|
|
||||||
// as.setSkin(skin);
|
|
||||||
if (isMonster) {
|
if (isMonster) {
|
||||||
node.setScale(-1, 1, 1);
|
node.setScale(-1, 1, 1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
import { Color, Component, EventTouch, sp, Vec3, _decorator } from "cc";
|
import { Color, Component, EventTouch, sp, Vec3, _decorator } from "cc";
|
||||||
import { LayerUtil } from "../../../../../extensions/oops-plugin-framework/assets/core/utils/LayerUtil";
|
import { LayerUtil } from "../../../../../extensions/oops-plugin-framework/assets/core/utils/LayerUtil";
|
||||||
import { smc } from "../../common/SingletonModuleComp";
|
import { smc } from "../../common/SingletonModuleComp";
|
||||||
|
// import Charactor, { CharactorDirection, CharactorState } from "../../map/view/map/charactor/Charactor";
|
||||||
import RoleSpineAnimator from "./RoleSpineAnimator";
|
import RoleSpineAnimator from "./RoleSpineAnimator";
|
||||||
|
|
||||||
const { ccclass, property } = _decorator;
|
const { ccclass, property } = _decorator;
|
||||||
@@ -18,30 +19,47 @@ const { ccclass, property } = _decorator;
|
|||||||
export class RoleSpine extends Component {
|
export class RoleSpine extends Component {
|
||||||
@property({ type: RoleSpineAnimator, tooltip: '动画控制器' })
|
@property({ type: RoleSpineAnimator, tooltip: '动画控制器' })
|
||||||
animator: RoleSpineAnimator = null!;
|
animator: RoleSpineAnimator = null!;
|
||||||
|
|
||||||
private spine!: sp.Skeleton;
|
private spine!: sp.Skeleton;
|
||||||
|
// private charactor!: Charactor;
|
||||||
|
|
||||||
onLoad() {
|
onLoad() {
|
||||||
|
// 角色控制组件
|
||||||
|
// this.charactor = this.addComponent(Charactor)!;
|
||||||
|
|
||||||
this.initAnimator();
|
this.initAnimator();
|
||||||
|
// this.setSkin("magic");
|
||||||
|
// this.animator.play("idle", true);
|
||||||
LayerUtil.setNodeLayer(LayerUtil.MAP, this.node);
|
LayerUtil.setNodeLayer(LayerUtil.MAP, this.node);
|
||||||
this.idle();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 初始化动画 */
|
/** 初始化动画 */
|
||||||
protected initAnimator() {
|
protected initAnimator() {
|
||||||
this.spine = this.animator.getComponent(sp.Skeleton)!;
|
this.spine = this.animator.getComponent(sp.Skeleton)!;
|
||||||
this.spine.setSkin('war');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// setState(value: CharactorState): void {
|
||||||
|
// switch (value) {
|
||||||
|
// case CharactorState.Idle:
|
||||||
|
// this.idle();
|
||||||
|
// break;
|
||||||
|
// case CharactorState.Run:
|
||||||
|
// this.walk();
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
setSkin(value: string): void {
|
setSkin(value: string): void {
|
||||||
|
console.log("RoleSpine setSkin", value);
|
||||||
this.spine.setSkin(value);
|
this.spine.setSkin(value);
|
||||||
}
|
}
|
||||||
|
play(animName: string, loop: boolean): void {
|
||||||
|
this.spine.setAnimation(0, animName, loop);
|
||||||
|
}
|
||||||
setAlpha(value: number): void {
|
setAlpha(value: number): void {
|
||||||
var color: Color = this.spine.color;
|
var color: Color = this.spine.color;
|
||||||
color.a = 255 * (value / 1);
|
color.a = 255 * (value / 1);
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
* @LastEditTime: 2022-08-04 15:26:38
|
* @LastEditTime: 2022-08-04 15:26:38
|
||||||
*/
|
*/
|
||||||
import { sp, _decorator ,Component} from "cc";
|
import { sp, _decorator ,Component} from "cc";
|
||||||
|
import { smc } from "../../common/SingletonModuleComp";
|
||||||
|
|
||||||
const { ccclass, property, requireComponent, disallowMultiple } = _decorator;
|
const { ccclass, property, requireComponent, disallowMultiple } = _decorator;
|
||||||
|
|
||||||
@@ -17,21 +18,72 @@ const { ccclass, property, requireComponent, disallowMultiple } = _decorator;
|
|||||||
export default class RoleSpineAnimator extends Component {
|
export default class RoleSpineAnimator extends Component {
|
||||||
private animName: string = "idle";
|
private animName: string = "idle";
|
||||||
private loop: boolean = true;
|
private loop: boolean = true;
|
||||||
|
private spine!: sp.Skeleton;
|
||||||
start() {
|
start() {
|
||||||
console.log("RoleSpineAnimator start");
|
this.spine = this.getComponent(sp.Skeleton)!;
|
||||||
this.playAnimation(this.animName, this.loop);
|
console.log("RoleSpineAnimator start smc.heros",smc.heros);
|
||||||
|
|
||||||
|
let heros=smc.heros
|
||||||
|
if(heros.length>0){
|
||||||
|
/**
|
||||||
|
* 取第一个heros
|
||||||
|
*/
|
||||||
|
|
||||||
|
this.spine.setSkin(heros[0])
|
||||||
|
console.log("RoleSpineAnimator setSkin", heros[0]);
|
||||||
|
switch (heros[0]) {
|
||||||
|
case 'war':
|
||||||
|
this.spine.setAnimation(0, 'idle', true)
|
||||||
|
break;
|
||||||
|
case 'magic':
|
||||||
|
this.spine.setAnimation(0, 'idle', true)
|
||||||
|
break;
|
||||||
|
case 'heath':
|
||||||
|
this.spine.setAnimation(0, 'idle', true)
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
this.spine.setAnimation(0, 'idle', true)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
//移除smc.heros[0],heros key 重新取
|
||||||
|
heros.splice(0,1)
|
||||||
|
smc.heros=heros
|
||||||
|
|
||||||
|
}else if(smc.monsters.length>0){
|
||||||
|
this.spine.setSkin(smc.monsters[0])
|
||||||
|
console.log("RoleSpineAnimator setSkin", smc.monsters[0]);
|
||||||
|
switch (smc.monsters[0]) {
|
||||||
|
case 'war':
|
||||||
|
this.spine.setAnimation(0, 'idle', true)
|
||||||
|
break;
|
||||||
|
case 'magic':
|
||||||
|
this.spine.setAnimation(0, 'idle', true)
|
||||||
|
break;
|
||||||
|
case 'heath':
|
||||||
|
this.spine.setAnimation(0, 'idle', true)
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
this.spine.setAnimation(0, 'idle', true)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
lateUpdate(dt: number) {
|
lateUpdate(dt: number) {
|
||||||
this.playAnimation(this.animName, this.loop);
|
|
||||||
|
}
|
||||||
|
getRandomInt(min: number, max: number): number {
|
||||||
|
min = Math.ceil(min);
|
||||||
|
max = Math.floor(max);
|
||||||
|
return Math.floor(Math.random() * (max - min + 1)) + min;
|
||||||
}
|
}
|
||||||
|
|
||||||
play(animName: string, loop: boolean) {
|
play(animName: string, loop: boolean) {
|
||||||
if (animName) {
|
if (animName) {
|
||||||
this.animName = animName;
|
this.animName = animName;
|
||||||
this.loop = loop;
|
this.loop = loop;
|
||||||
|
this.spine.setAnimation(0, this.animName, this.loop);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
}
|
}
|
||||||
@@ -43,9 +95,12 @@ export default class RoleSpineAnimator extends Component {
|
|||||||
* @param loop 是否循环播放
|
* @param loop 是否循环播放
|
||||||
*/
|
*/
|
||||||
protected playAnimation(animName: string, loop: boolean) {
|
protected playAnimation(animName: string, loop: boolean) {
|
||||||
|
console.log("RoleSpineAnimator playAnimation");
|
||||||
if (animName) {
|
if (animName) {
|
||||||
|
console.log("RoleSpineAnimator playAnimation animName", animName);
|
||||||
this.animName = animName;
|
this.animName = animName;
|
||||||
this.loop = loop;
|
this.loop = loop;
|
||||||
|
this.spine.setAnimation(0, this.animName, this.loop);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
}
|
}
|
||||||
|
|||||||
9
assets/script/game/role/view/monster.meta
Normal file
9
assets/script/game/role/view/monster.meta
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"ver": "1.2.0",
|
||||||
|
"importer": "directory",
|
||||||
|
"imported": true,
|
||||||
|
"uuid": "d5604362-ce57-4bc2-9a05-cb1ba2e170a2",
|
||||||
|
"files": [],
|
||||||
|
"subMetas": {},
|
||||||
|
"userData": {}
|
||||||
|
}
|
||||||
88
assets/script/game/role/view/monster/MonsterSpine.ts
Normal file
88
assets/script/game/role/view/monster/MonsterSpine.ts
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
/*
|
||||||
|
* @Author: dgflash
|
||||||
|
* @Date: 2022-08-04 15:08:35
|
||||||
|
* @LastEditors: dgflash
|
||||||
|
* @LastEditTime: 2022-08-04 15:26:26
|
||||||
|
*/
|
||||||
|
import { Color, Component, EventTouch, sp, Vec3, _decorator } from "cc";
|
||||||
|
import { LayerUtil } from "../../../../../../extensions/oops-plugin-framework/assets/core/utils/LayerUtil";
|
||||||
|
import { smc } from "../../../common/SingletonModuleComp";
|
||||||
|
// import Charactor, { CharactorDirection, CharactorState } from "../../map/view/map/charactor/Charactor";
|
||||||
|
import MonsterSpineAnimator from "./MonsterSpineAnimator";
|
||||||
|
|
||||||
|
const { ccclass, property } = _decorator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RPG SPINE角色模型
|
||||||
|
*/
|
||||||
|
@ccclass('MonsterSpine')
|
||||||
|
export class MonsterSpine extends Component {
|
||||||
|
@property({ type: MonsterSpineAnimator, tooltip: '动画控制器' })
|
||||||
|
animator: MonsterSpineAnimator = null!;
|
||||||
|
|
||||||
|
private spine!: sp.Skeleton;
|
||||||
|
// private charactor!: Charactor;
|
||||||
|
|
||||||
|
onLoad() {
|
||||||
|
// 角色控制组件
|
||||||
|
// this.charactor = this.addComponent(Charactor)!;
|
||||||
|
|
||||||
|
this.initAnimator();
|
||||||
|
// this.setSkin("magic");
|
||||||
|
// this.animator.play("idle", true);
|
||||||
|
LayerUtil.setNodeLayer(LayerUtil.MAP, this.node);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 初始化动画 */
|
||||||
|
protected initAnimator() {
|
||||||
|
this.spine = this.animator.getComponent(sp.Skeleton)!;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// setState(value: CharactorState): void {
|
||||||
|
// switch (value) {
|
||||||
|
// case CharactorState.Idle:
|
||||||
|
// this.idle();
|
||||||
|
// break;
|
||||||
|
// case CharactorState.Run:
|
||||||
|
// this.walk();
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
setSkin(value: string): void {
|
||||||
|
console.log("MonsterSpine setSkin", value);
|
||||||
|
this.spine.setSkin(value);
|
||||||
|
}
|
||||||
|
play(animName: string, loop: boolean): void {
|
||||||
|
this.spine.setAnimation(0, animName, loop);
|
||||||
|
}
|
||||||
|
setAlpha(value: number): void {
|
||||||
|
var color: Color = this.spine.color;
|
||||||
|
color.a = 255 * (value / 1);
|
||||||
|
this.spine.color = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
setPos(value: Vec3): void {
|
||||||
|
this.node.position = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
checkTouch(event: EventTouch): boolean {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
onDestroy() {
|
||||||
|
this.node.destroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
walk() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
idle() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
{"ver":"4.0.23","importer":"typescript","imported":true,"uuid":"482c216c-bef6-49fb-9060-37777b818f83","files":[],"subMetas":{},"userData":{}}
|
||||||
58
assets/script/game/role/view/monster/MonsterSpineAnimator.ts
Normal file
58
assets/script/game/role/view/monster/MonsterSpineAnimator.ts
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
* @Author: dgflash
|
||||||
|
* @Date: 2022-08-04 15:08:35
|
||||||
|
* @LastEditors: dgflash
|
||||||
|
* @LastEditTime: 2022-08-04 15:26:38
|
||||||
|
*/
|
||||||
|
import { sp, _decorator ,Component} from "cc";
|
||||||
|
|
||||||
|
const { ccclass, property, requireComponent, disallowMultiple } = _decorator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Spine状态机组件(主状态机),trackIndex为0
|
||||||
|
*/
|
||||||
|
@ccclass
|
||||||
|
@disallowMultiple
|
||||||
|
@requireComponent(sp.Skeleton)
|
||||||
|
export default class RoleSpineAnimator extends Component {
|
||||||
|
private animName: string = "idle";
|
||||||
|
private loop: boolean = true;
|
||||||
|
private spine!: sp.Skeleton;
|
||||||
|
start() {
|
||||||
|
this.spine = this.getComponent(sp.Skeleton)!;
|
||||||
|
console.log("RoleSpineAnimator start");
|
||||||
|
this.playAnimation(this.animName, this.loop);
|
||||||
|
}
|
||||||
|
|
||||||
|
lateUpdate(dt: number) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
play(animName: string, loop: boolean) {
|
||||||
|
if (animName) {
|
||||||
|
this.animName = animName;
|
||||||
|
this.loop = loop;
|
||||||
|
this.spine.setAnimation(0, this.animName, this.loop);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 播放动画
|
||||||
|
* @override
|
||||||
|
* @param animName 动画名
|
||||||
|
* @param loop 是否循环播放
|
||||||
|
*/
|
||||||
|
protected playAnimation(animName: string, loop: boolean) {
|
||||||
|
console.log("RoleSpineAnimator playAnimation");
|
||||||
|
if (animName) {
|
||||||
|
console.log("RoleSpineAnimator playAnimation animName", animName);
|
||||||
|
this.animName = animName;
|
||||||
|
this.loop = loop;
|
||||||
|
this.spine.setAnimation(0, this.animName, this.loop);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
{"ver":"4.0.23","importer":"typescript","imported":true,"uuid":"d3a795b7-3a93-41b0-be56-1d3f6666a1dd","files":[],"subMetas":{},"userData":{}}
|
||||||
33
assets/script/game/role/view/monster/RoleViewComp.ts
Normal file
33
assets/script/game/role/view/monster/RoleViewComp.ts
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* @Author: dgflash
|
||||||
|
* @Date: 2021-11-18 17:42:59
|
||||||
|
* @LastEditors: dgflash
|
||||||
|
* @LastEditTime: 2022-08-17 12:36:18
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { Vec3, _decorator } 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 { MonsterSpine } from "./MonsterSpine";
|
||||||
|
|
||||||
|
const { ccclass, property } = _decorator;
|
||||||
|
|
||||||
|
/** 角色显示组件 */
|
||||||
|
@ccclass('MonsterViewComp') // 定义为 Cocos Creator 组件
|
||||||
|
@ecs.register('MonsterView', false) // 定义为 ECS 组件
|
||||||
|
export class MonsterViewComp extends CCComp {
|
||||||
|
/** 角色动画 */
|
||||||
|
as: MonsterSpine = null!;
|
||||||
|
/** 角色控制器 */
|
||||||
|
|
||||||
|
/** 视图层逻辑代码分离演示 */
|
||||||
|
onLoad() {
|
||||||
|
this.as = this.getComponent(MonsterSpine);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
reset() {
|
||||||
|
this.node.destroy();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
{"ver":"4.0.23","importer":"typescript","imported":true,"uuid":"b5ce7cce-a8eb-439f-b034-13d10f8f9e2f","files":[],"subMetas":{},"userData":{}}
|
||||||
Reference in New Issue
Block a user