2023-10-23 18:56:01 +08:00
|
|
|
import { _decorator, sp } from "cc";
|
|
|
|
import GObject from "../GObject";
|
2023-10-24 02:32:06 +08:00
|
|
|
import { JNFrameInfo } from "../../../../../extensions/ngame/assets/ngame/sync/frame/JNSyncFrame";
|
|
|
|
import GFSMBase from "../fsm/GFSMBase";
|
2023-10-23 18:56:01 +08:00
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
|
|
|
|
//角色基类
|
|
|
|
export default abstract class GRoleBase<T> extends GObject<T>{
|
|
|
|
|
|
|
|
@property(sp.Skeleton)
|
|
|
|
spine:sp.Skeleton;
|
|
|
|
|
2023-10-24 02:32:06 +08:00
|
|
|
//状态机
|
|
|
|
fsm:GFSMBase;
|
|
|
|
|
2023-10-23 18:56:01 +08:00
|
|
|
onLoad(){
|
|
|
|
if(!this.spine) this.spine = this.node.getComponent(sp.Skeleton);
|
|
|
|
//如果没有生成则直接销毁
|
2023-10-24 02:32:06 +08:00
|
|
|
if(!this.spine) {
|
|
|
|
this.node.removeFromParent();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//创建角色状态机
|
|
|
|
this.fsm = this.fsmCreate();
|
|
|
|
|
2023-10-23 18:56:01 +08:00
|
|
|
}
|
|
|
|
|
2023-10-24 02:32:06 +08:00
|
|
|
//创建一个状态机
|
|
|
|
protected abstract fsmCreate():GFSMBase;
|
|
|
|
|
|
|
|
onSyncUpdate(dt: number,frame:JNFrameInfo, input?: T){
|
|
|
|
//更新状态机
|
|
|
|
this.fsm.onUpdate(dt);
|
2023-10-23 18:56:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|