public enum FSMStateType
{
None,
Default,
Idle,
Move,
}
Idle
public class IdleState : FSMState
{
public override void Action(FSMBase fsm)
{
fsm.PlayAnimation(AnimationParameters.Idle);
}
public override void EnterState(FSMBase fsm)
{
}
public override void ExitState(FSMBase fsm)
{
}
public override void InitState()
{
this.StateType = FSMStateType.Idle;
}
}
Move
public class MoveState : FSMState
{
public override void Action(FSMBase fsm)
{
fsm.PlayAnimation(AnimationParameters.Move);
fsm.Controller.Move();
}
public override void EnterState(FSMBase fsm)
{
}
public override void ExitState(FSMBase fsm)
{
}
public override void InitState()
{
this.StateType = FSMStateType.Move;
}
}
public enum FSMTriggerType
{
CanBeMove,
IsIdle,
}
是否移动
public class CanBeMoveTrigger : FSMTrigger
{
public override void Init()
{
this.TriggerType = FSMTriggerType.CanBeMove;
}
protected override bool Evaluate(FSMBase fsm)
{
return Mathf.Abs(Input.GetAxis("Horizontal")) > 0.5 || Mathf.Abs(Input.GetAxis("Vertical")) > 0.5;
}
}
是否静止
public class IsIdleTrigger : FSMTrigger
{ public override void Init()
{
this.TriggerType = FSMTriggerType.IsIdle;
}
protected override bool Evaluate(FSMBase fsm)
{
bool rst = Mathf.Abs(Input.GetAxis("Horizontal")) <= 0.5 && Mathf.Abs(Input.GetAxis("Vertical")) <= 0.5;
return rst;
}
}
public class FSMPlayer : FSMBase
{
public override void ConfigFSM()
{
IdleState idle = new IdleState();
idle.AddTrigger(FSMTriggerType.CanBeMove, FSMStateType.Move);
MoveState move = new MoveState();
move.AddTrigger(FSMTriggerType.IsIdle, FSMStateType.Idle);
AddState(idle);
AddState(move);
}
}
public class PlayerAnimationManager : CharacterAnimationManager
{
}