Exemplo n.º 1
0
        /// <summary>
        /// 初始化状态机
        /// </summary>
        private void ConfigFSM()
        {
            states = new List <FSMState>();
            IdleState idle = new IdleState();

            states.Add(idle);
            DeadState dead = new DeadState();

            states.Add(dead);

            idle.AddMap(FSMTriggerID.NoHealth, FSMStateID.Dead);
            idle.AddMap(FSMTriggerID.SawTarget, FSMStateID.Pursuit);

            PursuitState pursuit = new PursuitState();

            pursuit.AddMap(FSMTriggerID.NoHealth, FSMStateID.Dead);
            pursuit.AddMap(FSMTriggerID.ReachTarget, FSMStateID.Attacking);
            pursuit.AddMap(FSMTriggerID.LoseTarget, FSMStateID.Default);
            states.Add(pursuit);

            AttackingState attacking = new AttackingState();

            attacking.AddMap(FSMTriggerID.NoHealth, FSMStateID.Dead);
            attacking.AddMap(FSMTriggerID.WithoutAttackRange, FSMStateID.Patrolling);
            attacking.AddMap(FSMTriggerID.KilledTarget, FSMStateID.Default);
            states.Add(attacking);

            PatrollingState patrolling = new PatrollingState();

            patrolling.AddMap(FSMTriggerID.NoHealth, FSMStateID.Dead);
            patrolling.AddMap(FSMTriggerID.SawTarget, FSMStateID.Pursuit);
            patrolling.AddMap(FSMTriggerID.CompletePatrol, FSMStateID.Idle);
            states.Add(patrolling);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 状态库和映射表等等的初始化,硬
        /// </summary>
        private void Init()
        {
            //进行状态实例化
            IdleState      idle    = new IdleState();
            PursuitState   pursuit = new PursuitState();
            DeadState      dead    = new DeadState();
            AttackingState attack  = new AttackingState();

            //添加相应状态的映射
            //Idle->SawPlayer->Pursuit
            idle.AddFsmMap(FSMTriggerID.SawPlayer, FSMStateID.Pursuit);
            //Idle->NoHealth->Dead
            idle.AddFsmMap(FSMTriggerID.NoHealth, FSMStateID.Dead);
            idle.AddFsmMap(FSMTriggerID.ReachPlayer, FSMStateID.Attacking);
            //pursuit->NoHealth->Dead
            pursuit.AddFsmMap(FSMTriggerID.NoHealth, FSMStateID.Dead);
            pursuit.AddFsmMap(FSMTriggerID.ReachPlayer, FSMStateID.Attacking);
            pursuit.AddFsmMap(FSMTriggerID.LosePlayer, FSMStateID.Idle);
            attack.AddFsmMap(FSMTriggerID.NoHealth, FSMStateID.Dead);
            attack.AddFsmMap(FSMTriggerID.WithOutAttack, FSMStateID.Pursuit);
            attack.AddFsmMap(FSMTriggerID.LosePlayer, FSMStateID.Idle);


            //在状态库当中添加状态
            stateList.Add(idle);
            stateList.Add(pursuit);
            stateList.Add(dead);
            stateList.Add(attack);
        }