/// <summary> /// 状态机初始化 /// </summary> private void ConstructFSM() { //针对每一个行为进行初始化, 针对于每个行为进行状态到行为转变的添加 //巡逻 Patrol patrol = new Patrol(this); patrol.AddTransition(Transition.SawPlayer, FSMActionID.Chasing); patrol.AddTransition(Transition.NoHealth, FSMActionID.Dead); //追逐 Chase chase = new Chase(this); chase.AddTransition(Transition.ReachPalyer, FSMActionID.Attacking); chase.AddTransition(Transition.LostPlayer, FSMActionID.Patroling); chase.AddTransition(Transition.NoHealth, FSMActionID.Dead); //攻击 Attack attack = new Attack(this); attack.AddTransition(Transition.SawPlayer, FSMActionID.Chasing); attack.AddTransition(Transition.LostPlayer, FSMActionID.Patroling); attack.AddTransition(Transition.NoHealth, FSMActionID.Dead); //死亡 Dead dead = new Dead(this); dead.AddTransition(Transition.NoHealth, FSMActionID.Dead); //把状态列表进行初始化 AddFSMState(patrol); AddFSMState(chase); AddFSMState(attack); AddFSMState(dead); }
/// <summary> /// 初始化 /// </summary> void Init() { fsm = new FSMSystem(); agent = GetComponent <NavMeshAgent>(); anim = GetComponent <Animator>(); player = GameObject.FindWithTag("Player").transform; wayPoints = GameObject.FindGameObjectsWithTag("PatrolPoint"); patrol = new Patrol(fsm, transform, player, agent, anim, wayPoints); chase = new Chase(fsm, transform, player, agent, anim); attack = new Attack(fsm, transform, player, agent, anim); dead = new Dead(fsm, transform, player, agent, anim); hit = new Hit(fsm, transform, player, agent, anim); #region 改变状态 //看家玩家之后改变自己的状态为追击 看见玩家 -> 追击玩家 patrol.AddTransition(Transition.SawPlayer, FSMState.Chase); //巡逻过程中,可能会被玩家攻击 patrol.AddTransition(Transition.GetHit, FSMState.Hit); //巡逻中玩家进入它的范围 -> 开始攻击 patrol.AddTransition(Transition.ReachPlayer, FSMState.Attack); //追击的过程中,玩家移速过快,距离范围过大 丢失玩家 -> 开始巡逻 chase.AddTransition(Transition.LostPlayer, FSMState.Patrol); //追击过程中,追到了玩家 -> 开始攻击 chase.AddTransition(Transition.ReachPlayer, FSMState.Attack); //收到攻击 chase.AddTransition(Transition.GetHit, FSMState.Hit); //攻击过程中 玩家移动,只要还在距离范围内,就会触发追击,直至玩家超出指定距离 attack.AddTransition(Transition.SawPlayer, FSMState.Chase); //攻击过程中,玩家突然死亡,或者距离超出 就去巡逻 attack.AddTransition(Transition.LostPlayer, FSMState.Patrol); //收到攻击 attack.AddTransition(Transition.GetHit, FSMState.Hit); //被击打的时候,也会存在丢失玩家的情况 hit.AddTransition(Transition.LostPlayer, FSMState.Patrol); #endregion fsm.AddState(patrol); fsm.AddState(chase); fsm.AddState(attack); fsm.AddState(dead); fsm.AddState(hit); }
/// <summary> /// 状态机初始化 /// </summary> private void ConstructFSM() { //进行路点初始化 pointList = GameObject.FindGameObjectsWithTag("PatrolPoint"); Transform[] wayPoints = new Transform[pointList.Length]; int i = 0; foreach (GameObject obj in pointList) { wayPoints[i] = obj.transform; i++; } //针对每一个行为进行初始化, 针对于每个行为进行状态到行为转变的添加 //巡逻 Patrol patrol = new Patrol(wayPoints, this); patrol.AddTransition((int)Transition.SawPlayer, (int)FSMActionID.Chasing); patrol.AddTransition((int)Transition.NoHealth, (int)FSMActionID.Dead); //追逐 Chase chase = new Chase(wayPoints, this); chase.AddTransition((int)Transition.ReachPalyer, (int)FSMActionID.Attacking); chase.AddTransition((int)Transition.LostPlayer, (int)FSMActionID.Patroling); chase.AddTransition((int)Transition.NoHealth, (int)FSMActionID.Dead); //攻击 Attack attack = new Attack(wayPoints, this); attack.AddTransition((int)Transition.SawPlayer, (int)FSMActionID.Chasing); attack.AddTransition((int)Transition.LostPlayer, (int)FSMActionID.Patroling); attack.AddTransition((int)Transition.NoHealth, (int)FSMActionID.Dead); //死亡 Dead dead = new Dead(); dead.AddTransition((int)Transition.NoHealth, (int)FSMActionID.Dead); //把状态列表进行初始化 AddFSMState(patrol); AddFSMState(chase); AddFSMState(attack); AddFSMState(dead); StartFSM(patrol); }
protected override void InitialiseBrain() { brain = new StateMachine.FSM(this); var patrol = new Patrol(); var dead = new Dead(); patrol.AddTransition(dead, () => { return(!IsAlive); }); brain.AddState(patrol); brain.AddState(dead); brain.Initialise("Patrol"); }
private void InitFSM() { fsm = new FSMsystem(); FSMstate patrol = new Patrol(fsm); patrol.AddTransition(Transition.SpotPlayer, StateID.Chase); fsm.AddState(patrol); FSMstate chase = new Chase(fsm); chase.AddTransition(Transition.LostPlayer, StateID.Patrol); fsm.AddState(chase); }
protected override void InitialiseBrain() { brain = new StateMachine.FSM(this); var patrol = new Patrol(); var dying = new Dying(CorpseAppearance); var dead = new Dead(); patrol.AddTransition(dying, () => { return(!IsAlive); }); dying.AddTransition(dead, () => { return(dying.HitGround); }); brain.AddState(patrol); brain.AddState(dying); brain.AddState(dead); brain.Initialise("Patrol"); }