Ejemplo n.º 1
0
 /// <summary>
 /// Switches to new state in the state dictionary
 /// </summary>
 /// <param name="nextstate"></param>
 void SwitchToNewState(Type nextstate)
 {
     _currentState?.OnStateExit();
     _currentState = _availableStates[nextstate];
     onStateChanged?.Invoke(_currentState);
     _currentState?.OnStateEnter();
     Debug.Log("Game State Changed To: " + _currentState.ToString());
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Switches to new state in the state dictionary
 /// </summary>
 /// <param name="nextstate"></param>
 void SwitchToNewState(Type nextstate)
 {
     _currentState?.OnStateExit();
     _currentState = _availableStates[nextstate];
     onStateChanged?.Invoke(_currentState);
     _currentState?.OnStateEnter();
     Debug.LogFormat("{0} state Changed To: " + _currentState.ToString(), gameObject.name);
 }
Ejemplo n.º 3
0
    /// <summary>
    /// Begins the process to start a new State
    /// </summary>
    /// <param name="NextAIState"></param>
    protected void StartNewState(BaseAIState NextAIState)
    {
        if (NextAIState == CurrentState)
        {
            return;
        }

        if (CurrentState != null)
        {
            CurrentState.OnStateEnded();
        }
        CurrentState = NextAIState;
        if (!CurrentState.bIsInitialized)
        {
            CurrentState.InitilalizeState(this);
        }
        CurrentState.OnStateBegin();
    }
Ejemplo n.º 4
0
    // Update is called once per frame
    private void Update()
    {
        if (Current_state == null && _available_states != null)
        {
            // grab first value of dictionary of states by default
            Current_state = _available_states.Values.First();
            //Debug.Log(_available_states.Values.First());
        }

        // Calls the next Tick() of the state it is in.
        // then returns with the next State
        var nextState = Current_state?.Tick();

        // changes next state if not null, needs return type
        if (nextState != null &&
            nextState != Current_state?.GetType())
        {
            SwitchToNewState(nextState);
        }
        // Debug.Log("NULL NEXT same STATE, are we safe?");
    }
Ejemplo n.º 5
0
    // Update is called once per frame
    private void Update()
    {
        if (Current_state == null)
        {
            Current_state = _available_states.Values.First();
        }

        // Calls the next Tick() of the state it is in.
        // then returns with the next State
        var nextState = Current_state?.Tick();

        if (nextState != null &&
            nextState != Current_state?.GetType())
        {
            SwitchToNewState(nextState);
        }
        else if (nextState == null)
        {
            Debug.Log("NULL NEXT STATE, are we safe?");
        }
    }
Ejemplo n.º 6
0
 private void SwitchToNewState(Type nextState)
 {
     Current_state = _available_states[nextState];
     OnStateChanged?.Invoke(Current_state);
 }