状态机接口笔记

//状态机接口

Public interface IState{

   Void Enter(EntityBase entity,params object[] args);

}

//不同状态继承状态机

Public class StateAttack:Istate{

Public void Enter(EntityBase  entity,params object[] args ){

}

}

//状态枚举

public enum AniState

{   None,

    Idle,

    Move,

    Attack,

}

Dictionary<AniState,IState> fsm = new Dictionary<AniState,Istate>();

Void Init(){

fsm.Add(AniState,Idle,new StateAttack());

}

//使用状态切换

Void ChangeStatus(EntityBase entity,AniState  targetState ,params  object[] args){

fsm[targetState].Enter(entity,args);

}

posted @ 2021-06-23 09:57  T驱动  阅读(51)  评论(0编辑  收藏  举报