Exemple #1
0
        /// <summary>
        ///   Awake.
        /// </summary>
        private void Awake()
        {
            _stateMachineController = new StateMachineController();
            _navMeshAgent           = GetComponent <NavMeshAgent>();
            _entity = GetComponent <Entity>();

            EntityIdle        entityIdle        = new EntityIdle();
            EntityChasePlayer entityChasePlayer = new EntityChasePlayer(_navMeshAgent);
            EntityAttack      entityAttack      = new EntityAttack();
            EntityDead        entityDead        = new EntityDead();

            _stateMachineController.Add(entityIdle);
            _stateMachineController.Add(entityChasePlayer);
            _stateMachineController.Add(entityAttack);

            _stateMachineController.AddAnyStateTransition(entityDead, () => _entity.IsDead);

            Player player = FindObjectOfType <Player>();

            _stateMachineController.AddStateTransition(entityIdle,
                                                       entityChasePlayer,
                                                       () => FlatDistance(_navMeshAgent.transform.position, player.transform.position) < 5);
            _stateMachineController.AddStateTransition(entityChasePlayer,
                                                       entityAttack,
                                                       () => FlatDistance(_navMeshAgent.transform.position, player.transform.position) < 2);

            _stateMachineController.ChangeState(entityIdle);
        }
Exemple #2
0
        public void second_change_state_switches_to_second_state()
        {
            StateMachineController stateMachineController = new StateMachineController();
            IState firstState = Substitute.For <IState>();

            stateMachineController.Add(firstState);
            IState secondState = Substitute.For <IState>();

            stateMachineController.Add(secondState);

            stateMachineController.ChangeState(firstState);
            Assert.AreSame(firstState, stateMachineController.CurrentState);

            stateMachineController.ChangeState(secondState);
            Assert.AreSame(secondState, stateMachineController.CurrentState);
        }
Exemple #3
0
    void Start()
    {
        // Initialise the accessable script components
        _agentData      = GetComponent <AgentData>();
        _agentActions   = GetComponent <AgentActions>();
        _agentSenses    = GetComponentInChildren <Sensing>();
        _agentInventory = GetComponentInChildren <InventoryController>();


        StateMachine = new StateMachineController <AI>(this);  //Creates a state machine for this AI Agent
        StateMachine.ChangeState(GotoEnemyBaseState.Instance); //Set the initial state of the AI Player
    }
Exemple #4
0
        public void transition_does_not_switch_state_when_condition_is_not_met()
        {
            StateMachineController stateMachineController = new StateMachineController();
            IState firstState = Substitute.For <IState>();

            stateMachineController.Add(firstState);
            IState secondState = Substitute.For <IState>();

            stateMachineController.Add(secondState);

            bool ShouldTransitionToState() => false;

            stateMachineController.AddStateTransition(firstState, secondState, ShouldTransitionToState);

            stateMachineController.ChangeState(firstState);
            Assert.AreSame(firstState, stateMachineController.CurrentState);

            stateMachineController.Tick();
            Assert.AreSame(firstState, stateMachineController.CurrentState);
        }