46 lines
1.3 KiB
TypeScript
46 lines
1.3 KiB
TypeScript
import { _decorator, Animation, AnimationClip } from 'cc'
|
|
import State from '../../Base/State'
|
|
import StateMachine, { getInitParamsNumber, getInitParamsTrigger } from '../../Base/StateMachine'
|
|
import { EntityTypeEnum, TexturePathEnum, EntityStateEnum, ParamsNameEnum } from '../../Enum'
|
|
const { ccclass, property } = _decorator
|
|
|
|
@ccclass('BulletStateMachine')
|
|
export class BulletStateMachine extends StateMachine {
|
|
type: EntityTypeEnum
|
|
init(type: EntityTypeEnum) {
|
|
this.type = type
|
|
this.animationComponent = this.node.addComponent(Animation)
|
|
|
|
this.initParams()
|
|
this.initStateMachines()
|
|
this.initAnimationEvent()
|
|
}
|
|
|
|
initParams() {
|
|
this.params.set(ParamsNameEnum.Idle, getInitParamsTrigger())
|
|
}
|
|
|
|
initStateMachines() {
|
|
this.stateMachines.set(ParamsNameEnum.Idle, new State(this, `${this.type}${EntityStateEnum.Idle}`))
|
|
}
|
|
|
|
initAnimationEvent() {
|
|
|
|
}
|
|
|
|
run() {
|
|
switch (this.currentState) {
|
|
case this.stateMachines.get(ParamsNameEnum.Idle):
|
|
if (this.params.get(ParamsNameEnum.Idle).value) {
|
|
this.currentState = this.stateMachines.get(ParamsNameEnum.Idle)
|
|
} else {
|
|
this.currentState = this.currentState
|
|
}
|
|
break
|
|
default:
|
|
this.currentState = this.stateMachines.get(ParamsNameEnum.Idle)
|
|
break
|
|
}
|
|
}
|
|
}
|