dd
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
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 RoleSpineAnimator from "./RoleSpineAnimator";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
@@ -18,30 +19,47 @@ const { ccclass, property } = _decorator;
|
||||
export class RoleSpine extends Component {
|
||||
@property({ type: RoleSpineAnimator, tooltip: '动画控制器' })
|
||||
animator: RoleSpineAnimator = 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);
|
||||
this.idle();
|
||||
}
|
||||
|
||||
/** 初始化动画 */
|
||||
protected initAnimator() {
|
||||
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 {
|
||||
console.log("RoleSpine 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);
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
* @LastEditTime: 2022-08-04 15:26:38
|
||||
*/
|
||||
import { sp, _decorator ,Component} from "cc";
|
||||
import { smc } from "../../common/SingletonModuleComp";
|
||||
|
||||
const { ccclass, property, requireComponent, disallowMultiple } = _decorator;
|
||||
|
||||
@@ -17,21 +18,72 @@ const { ccclass, property, requireComponent, disallowMultiple } = _decorator;
|
||||
export default class RoleSpineAnimator extends Component {
|
||||
private animName: string = "idle";
|
||||
private loop: boolean = true;
|
||||
|
||||
private spine!: sp.Skeleton;
|
||||
start() {
|
||||
console.log("RoleSpineAnimator start");
|
||||
this.playAnimation(this.animName, this.loop);
|
||||
this.spine = this.getComponent(sp.Skeleton)!;
|
||||
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) {
|
||||
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) {
|
||||
if (animName) {
|
||||
this.animName = animName;
|
||||
this.loop = loop;
|
||||
this.spine.setAnimation(0, this.animName, this.loop);
|
||||
}
|
||||
else {
|
||||
}
|
||||
@@ -43,9 +95,12 @@ export default class RoleSpineAnimator extends Component {
|
||||
* @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 {
|
||||
}
|
||||
|
||||
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