void Start() { Dictionary <Type, IAiFsmState> state_pool = new Dictionary <Type, IAiFsmState>(); //手动初始化状态池,这一步是不是可以通过什么途径通用化?存疑 state_pool.Add(typeof(AiLaughState), new AiLaughState(this)); state_pool.Add(typeof(AiMoveState), new AiMoveState(this)); m_fsm_ctrl = new MonoFSMContorl <IAiFsmState>(this, "simple_ai_fsm_contorl", state_pool, typeof(AiLaughState)); //测试监听器 m_fsm_ctrl.AddListenerToSwitch((mes) => { Debug.Log("ListenerToSwitch Last:" + mes.LastStateType.ToString() + " - Cur:" + mes.CurStateType.ToString()); }); //监听玩家状态改变 m_player_fsm.AddListenerToSwitch((mes) => { if (mes.CurStateType == typeof(PlayerIdleState)) //根据玩家当前状态切换自身状态 { m_fsm_ctrl.SwitchTo(typeof(AiLaughState)); } else { m_fsm_ctrl.SwitchTo(typeof(AiMoveState)); } }); }
public void SwitchTo(Type state) { m_player_fsm.SwitchTo(state); }