void InitFSM() { fsm = new FSMSystem(); FSMState sleepState = new SleepState(fsm); sleepState.AddTransition(Transition.Open, StateID.Idle); FSMState IdleState = new IdleState(fsm); IdleState.AddTransition(Transition.Close, StateID.Sleep); IdleState.AddTransition(Transition.SeePlayer, StateID.Patrol); IdleState.AddTransition(Transition.Shopping, StateID.GoOut); IdleState.AddTransition(Transition.StartPlay, StateID.Play); FSMState patrolState = new PatrolState(fsm); patrolState.AddTransition(Transition.Open, StateID.Idle); patrolState.AddTransition(Transition.SeePlayer, StateID.Chase); FSMState chaseState = new ChaseState(fsm); chaseState.AddTransition(Transition.LostPlayer, StateID.Patrol); chaseState.AddTransition(Transition.FindEnemy, StateID.Bark); FSMState barkState = new BarkState(fsm); barkState.AddTransition(Transition.LostPlayer, StateID.Patrol); FSMState gooutState = new GoOutState(fsm); gooutState.AddTransition(Transition.Back, StateID.ComeBack); gooutState.AddTransition(Transition.SeePlayer, StateID.Patrol); FSMState comebackState = new ComeBackState(fsm); comebackState.AddTransition(Transition.Open, StateID.Idle); FSMState playState = new PlayState(fsm); playState.AddTransition(Transition.Open, StateID.Idle); playState.AddTransition(Transition.Close, StateID.Sleep); playState.AddTransition(Transition.SeePlayer, StateID.Patrol); playState.AddTransition(Transition.Shopping, StateID.GoOut); fsm.AddState(sleepState); fsm.AddState(IdleState); fsm.AddState(patrolState); fsm.AddState(chaseState); fsm.AddState(barkState); fsm.AddState(comebackState); fsm.AddState(gooutState); fsm.AddState(playState); }
/// <summary> /// 生成状态机,将所有状态和转换条件添加进去,并设置初始状态 /// </summary> private void MakeFSM() { fsm = new FSMSystem(); MenuState menuState = new MenuState(fsm, this); menuState.AddTransition(Transition.StartClickButton, StateID.Play); menuState.AddTransition(Transition.RestartToGame, StateID.Play); //todo PlayState playState = new PlayState(fsm, this); playState.AddTransition(Transition.PauseClickButton, StateID.Menu); //todo fsm.AddState(menuState); fsm.AddState(playState); fsm.Start(StateID.Menu); }