void InitFSM() { IdleState idleState = new IdleState(gameObject); RunState runState = new RunState(gameObject); ThrowState throwState = new ThrowState(gameObject); DeadState deadState = new DeadState(gameObject); // 注册切换条件 对应的 状态 idleState.AddTransition(FSMTransition.IdleToRun, FSMStateId.Run); runState.AddTransition(FSMTransition.RunToIdle, FSMStateId.Idle); idleState.AddTransition(FSMTransition.IdleToThrow, FSMStateId.Throw); runState.AddTransition(FSMTransition.RunToThrow, FSMStateId.Throw); throwState.AddTransition(FSMTransition.ThrowToIdle, FSMStateId.Idle); idleState.AddTransition(FSMTransition.IdleToDead, FSMStateId.Dead); runState.AddTransition(FSMTransition.RunToDead, FSMStateId.Dead); throwState.AddTransition(FSMTransition.ThrowToDead, FSMStateId.Dead); system.AddState(idleState); system.AddState(runState); system.AddState(throwState); system.AddState(deadState); system.Start(FSMStateId.Idle); }
void Start() { fSMSystem = new FSMSystem(); fSMState = new Example_Start(fSMSystem); fSMState.AddTransition(Transition.RuningTrans, StateID.Runing); fSMSystem.AddState(fSMState); fSMState = new Example_Runing(fSMSystem); fSMState.AddTransition(Transition.StartTrans, StateID.Start); fSMSystem.AddState(fSMState); fSMSystem.Start(); }
/// <summary> /// 初始化状态机 /// </summary> void InitFSM() { fsm = new FSMSystem(); PatrolState patrolState = new PatrolState(waypoints, gameObject, player); // 巡逻状态添加事件,发现玩家则进行追逐 patrolState.AddTransition(Transition.SawPlayer, StateId.Chase); ChaseState chaseState = new ChaseState(gameObject, player); // 追逐状态添加事件,丢失玩家则进行巡逻 chaseState.AddTransition(Transition.LostPlayer, StateId.Patrol); fsm.AddState(patrolState); fsm.AddState(chaseState); // 初始状态是巡逻状态 fsm.Start(StateId.Patrol); }
void InitFSM() { system = new FSMSystem(); PatrolState patrolState = new PatrolState(wayPoints, gameObject, player); ChaseState chaseState = new ChaseState(gameObject, player); // 注册切换条件 对应的 状态 patrolState.AddTransition(FSMTransition.SawPlayer, FSMStateId.Chase); chaseState.AddTransition(FSMTransition.LostPlayer, FSMStateId.Patrol); system.AddState(patrolState); system.AddState(chaseState); system.Start(FSMStateId.Patrol); }
/// <summary> /// 初始化状态机 /// </summary> void InitFSM() { fsm = new FSMSystem(); PatrolState partolState = new PatrolState(wayPoints, gameObject, player); partolState.AddTransition(Transition.SawPlayer, StateID.Chase);// 这里只有一个,如果还有其他转换条件,可以继续添加 ChaseState chaseState = new ChaseState(gameObject, player); chaseState.AddTransition(Transition.LostPlayer, StateID.Patrol); fsm.AddState(partolState); fsm.AddState(chaseState); fsm.Start(StateID.Patrol); }
void InitFSM() { fsm = new FSMSystem(); PatrolState patrolState = new PatrolState(waypoints, this.gameObject, player); patrolState.AddTransition(Transition.SawPlayer, StateID.Chase); ChaseState chaseState = new ChaseState(this.gameObject, player); chaseState.AddTransition(Transition.LostPlayer, StateID.Patrol); fsm.AddState(patrolState); fsm.AddState(chaseState); fsm.Start(StateID.Patrol); }
void InitFSM() { fsm = new FSMSystem(); PatrolState patrol = new PatrolState(wayPoint, npc, player); patrol.AddTransition(Transition.SawPlayer, StateId.Chase); ChaseState chase = new ChaseState(npc, player); chase.AddTransition(Transition.LostPlayer, StateId.Patrol); fsm.AddState(patrol); fsm.AddState(chase); fsm.Start(StateId.Patrol); }
/// <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); }
/// <summary> /// 初始化状态机 /// </summary> public void InitFSM() { fsm = new FSMSystem(); PatrolState patrolState = new PatrolState(this.gameObject.transform.position, this.gameObject); patrolState.AddTransition(Transition.SawPlayer, StateID.Chase); patrolState.SetNavAgent(navAgent); ChaseState chaseState = new ChaseState(this.gameObject); chaseState.AddTransition(Transition.LostPlayer, StateID.Patrol); chaseState.SetNavAgent(navAgent); this.transform.GetComponent <SphereCollider>().enabled = true; fsm.AddState(patrolState); fsm.AddState(chaseState); fsm.Start(StateID.Patrol); }