动画重做,需要修改

This commit is contained in:
2024-11-29 13:36:06 +08:00
parent baf0717b0a
commit 8d97e1b3e0
46 changed files with 6757 additions and 9 deletions

View File

@@ -0,0 +1,50 @@
/*
* @Author: dgflash
* @Date: 2022-08-04 15:08:35
* @LastEditors: dgflash
* @LastEditTime: 2022-08-04 15:26:38
*/
import { sp, _decorator } from "cc";
import AnimatorSpine from "../../../../extensions/oops-plugin-framework/assets/libs/animator/AnimatorSpine";
const { ccclass, property, requireComponent, disallowMultiple } = _decorator;
/**
* Spine状态机组件主状态机trackIndex为0
*/
@ccclass
@disallowMultiple
@requireComponent(sp.Skeleton)
export default class HeroAnmComp extends AnimatorSpine {
private animName: string = "Idle";
private loop: boolean = true;
start() {
super.start();
}
lateUpdate(dt: number) {
}
/**
* 播放动画
* @override
* @param animName 动画名
* @param loop 是否循环播放
*/
protected playAnimation(animName: string, loop: boolean) {
if (animName) {
this.animName = animName;
this.loop = loop;
this._spine.setAnimation(0, animName, loop);
}
else {
this._spine.clearTrack(0);
}
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "4ba4ac2e-cfcb-45df-8aea-e13919f56d52",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -5,8 +5,6 @@
* @LastEditTime: 2022-08-04 15:26:26
*/
import { Color, Component, EventTouch, sp, Vec3, _decorator ,Animation, AnimationClip, AnimationState,} from "cc";
import { LayerUtil } from "../../../../extensions/oops-plugin-framework/assets/core/utils/LayerUtil";
import { smc } from "../../../script/game/common/SingletonModuleComp";
const { ccclass, property } = _decorator;
@@ -17,15 +15,11 @@ const { ccclass, property } = _decorator;
export class HeroSpine extends Component {
@property(Animation)
animator: Animation = null!;
idle_clip: AnimationClip = null!;
atk_clip: AnimationClip = null!;
move_clip: AnimationClip = null!;
default_clip:string = "";
onLoad() {
// 角色控制组件
this.initAnimator();
LayerUtil.setNodeLayer(LayerUtil.MAP, this.node);
this.idle_clip = this.animator.clips[0];
this.atk_clip = this.animator.clips[1];
this.move_clip = this.animator.clips[2];

View File

@@ -0,0 +1,93 @@
/*
* @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 ,Animation, AnimationClip, AnimationState,} from "cc";
import { LayerUtil } from "../../../../extensions/oops-plugin-framework/assets/core/utils/LayerUtil";
import { smc } from "../../../script/game/common/SingletonModuleComp";
const { ccclass, property } = _decorator;
/**
* SPINE角色模型
*/
@ccclass('HeroSpine')
export class HeroSpine extends Component {
@property(Animation)
animator: Animation = null!;
idle_clip: AnimationClip = null!;
atk_clip: AnimationClip = null!;
move_clip: AnimationClip = null!;
default_clip:string = "";
onLoad() {
// 角色控制组件
this.initAnimator();
LayerUtil.setNodeLayer(LayerUtil.MAP, this.node);
this.idle_clip = this.animator.clips[0];
this.atk_clip = this.animator.clips[1];
this.move_clip = this.animator.clips[2];
this.default_clip=this.move_clip.name;
let animation = this.animator.getComponent(Animation);
animation.on(Animation.EventType.FINISHED, this.onAnimationEvent, this)
}
protected start(): void {
this.move();
}
/** 初始化动画 */
protected initAnimator() {
this.animator=this.node.getChildByName("anm").getComponent(Animation);
// console.log("mon spine init",this.animator);
}
in_playing(){
if(this.animator.getState(this.atk_clip.name).isPlaying) return true;
if(this.animator.getState(this.idle_clip.name).isPlaying) return true;
if(this.animator.getState(this.move_clip.name).isPlaying) return true;
return false;
}
onAnimationEvent(type: Animation.EventType, state: AnimationState){
if(type==Animation.EventType.FINISHED){
// console.log("animator end",state.name);
if(state.name==this.atk_clip.name){
this.default();
}
}
}
change_default(value:string){
// console.log("change default",value);
this.default_clip=value;
}
default() {
if(!this.in_playing()){
// console.log("do default");
this.animator.play(this.default_clip);
}
}
idle(){
if(!this.in_playing()){
console.log("do idle");
this.animator.play(this.idle_clip.name);
}
}
atk() {
// console.log("do atk");
this.animator.play(this.atk_clip.name);
}
move(){
if(!this.animator.getState(this.move_clip.name).isPlaying) {
console.log("doing move");
this.animator.play(this.move_clip.name);
}
}
onDestroy() {
this.node.destroy();
}
}

View File

@@ -0,0 +1 @@
{"ver":"4.0.23","importer":"typescript","imported":true,"uuid":"8bf79351-aad1-411f-a117-97ccba1fe15f","files":[],"subMetas":{},"userData":{}}

View File

@@ -271,11 +271,11 @@ export class HeroViewComp extends CCComp {
this.status=type
if(type == "idle"){
this.as.idle()
this.as.change_default("idle")
// this.as.change_default("idle")
}
if(type == "move"){
this.as.move()
this.as.change_default("move")
// this.as.change_default("move")
}
}
move(dt: number){