3.7.4 spine不同步转3.8.1 修复3.8.1 动画

This commit is contained in:
DESKTOP-5RP3AKU\Jisol
2023-11-01 04:49:52 +08:00
parent 6ebed0b45e
commit 2825c1e1d4
328 changed files with 1222 additions and 362 deletions

View File

@@ -1,6 +1,7 @@
import { sp } from "cc";
import GFSMBase, { GFSMProcessEnum, GFSMProcessInfo, GFSMProcessMode } from "./GFSMBase";
import GObject from "../GObject";
import { JNFrameInfo } from "../../../../../extensions/ngame/assets/ngame/sync/frame/JNSyncFrame";
//角色动画名称枚举
export enum GFSMBattleAminEnum {
@@ -33,8 +34,9 @@ export abstract class GFSMAnimBase extends GFSMBase{
//动画Root
spine:sp.Skeleton;
events:{event:string,fun:Function}[] = [];
starts:{name:string,fun:Function}[] = [];
events:{[key:string]:Function[]}= {};
starts:{[key:string]:Function[]}= {};
ends:{[key:string]:Function[]}= {};
constructor(spine:sp.Skeleton,trackIndex:number = 0){
super();
@@ -42,8 +44,10 @@ export abstract class GFSMAnimBase extends GFSMBase{
this.trackIndex = trackIndex;
//设置监听
this.spine.setEventListener(this.onEventListener.bind(this));
//因为SpineBUG所以不使用Spine监听 采用自己调用
this.spine.setStartListener(this.onStartListener.bind(this));
//设置结束监听
this.spine.setCompleteListener(this.onEndListener.bind(this));
// //因为SpineBUG所以不使用Spine监听 采用自己调用
// this.spine.setStartListener(this.onStartListener.bind(this));
}
open(){
@@ -56,49 +60,75 @@ export abstract class GFSMAnimBase extends GFSMBase{
//添加事件监听
addEventListener(event:string,fun:Function){
this.events.push({
event,
fun,
})
if(!this.events[event]) this.events[event] = [];
this.events[event].push(fun);
}
//监听动画开始播放
addStartListener(name:string,fun:Function){
this.starts.push({
name,
fun,
})
if(!this.starts[name]) this.starts[name] = [];
this.starts[name].push(fun);
}
//监听动画结束播放
addEndListener(name:string,fun:Function){
if(!this.ends[name]) this.ends[name] = [];
this.ends[name].push(fun);
}
//删除事件监听
delEventListener(event:string,fun:Function){
if(!this.events[event]) this.events[event] = [];
let index = this.events[event].indexOf(fun);
if(index >= 0) this.events[event].splice(index,1)
}
//删除动画开始播放
delStartListener(name:string,fun:Function){
if(!this.starts[name]) this.starts[name] = [];
let index = this.starts[name].indexOf(fun);
if(index >= 0) this.starts[name].splice(index,1)
}
//删除动画结束播放
delEndListener(name:string,fun:Function){
if(!this.ends[name]) this.ends[name] = [];
let index = this.ends[name].indexOf(fun);
if(index >= 0) this.ends[name].splice(index,1)
}
onEventListener(entry: sp.spine.TrackEntry, ev: sp.spine.Event){
this.events.forEach(item => {
if(item.event == ev.data.name){
item.fun();
}
if(!this.events[ev.data.name]) this.events[ev.data.name] = [];
this.events[ev.data.name].forEach(fun => {
fun();
});
}
onStartListener(entry: sp.spine.TrackEntry){
this.starts.forEach(item => {
if(entry.animation.name == item.name){
item.fun();
}
if(!this.starts[entry.animation.name]) this.starts[entry.animation.name] = [];
this.starts[entry.animation.name].forEach(fun => {
fun();
});
}
onEndListener(entry: sp.spine.TrackEntry){
if(!this.ends[entry.animation.name]) this.ends[entry.animation.name] = [];
this.ends[entry.animation.name].forEach(fun => {
fun();
});
}
// 流程图
process: { [key: number]: GFSMProcessAnimInfo; } = {}
execute(process:GFSMProcessAnimInfo,dt:number){
execute(process:GFSMProcessAnimInfo,dt:number,frame:JNFrameInfo){
process.ifTo = process.ifTo || [];
process.to = process.to || [];
process.mode = GFSMProcessMode.WaitExecute;
process.execute = this.tick.bind(this);
super.execute(process,dt);
super.execute(process,dt,frame);
}
//-1 继续播放 0 重新执行流程 * 指定分支
tick(dt:number,info:GFSMProcessAnimInfo){
tick(dt:number,info:GFSMProcessAnimInfo,frame:JNFrameInfo){
//判断是否会切换动画 (默认不切换)
let to = GFSMProcessEnum.Wait;
@@ -121,8 +151,9 @@ export abstract class GFSMAnimBase extends GFSMBase{
//播放动画
if(!info.track){
console.log(`播放动画-${this.spine.getComponent(GObject).nId}-`,info);
console.log(`${frame.index} 播放动画-${this.spine.getComponent(GObject).nId}-`,info);
info.track = this.spine.setAnimation(this.trackIndex,info.animName,!!info.isLoop);
this.onStartListener(info.track);
}
return to;