Example #1
0
        /// <summary>
        /// Switch the currentstate to a specific new State.
        /// </summary>
        /// <param name="newState">
        /// The state object to set as the currentState</param>
        /// <returns></returns>
        protected virtual State SetState(State newState)
        {
            if (newState && newState != currentState)
            {
                lastState    = currentState;
                currentState = newState;
                if (lastState)
                {
                    lastState.StateExit();
                }
                currentState.StateEnter();
                if (enableDebug)
                {
                    try
                    {
                        Debug.Log($"{lastState.GetType()} to {currentState.GetType()}");
                    }
                    catch (NullReferenceException)
                    {
                        Debug.Log($"{currentState.GetType()}");
                    }
                }

                return(currentState);
            }

            return(null);
        }
Example #2
0
    public void SetState(int stateId)
    {
        if (stateId < 0 || stateId >= states.Length)
        {
            Debug.LogError("[StateManager.SetStates] stateId: " + stateId + " out of array index");
            return;
        }

        if (states[stateId] == null)
        {
            Debug.LogError("[StateManager.SetStates] the new state is null");
            return;
        }

        if (curState != null)
        {
            Debug.Log(curState.GetType().ToString() + " Exit");
            nextStateId = stateId;
            curState.StateExit();
        }
        lastStateId = GetCurStateId();
        curState    = states[stateId];
        Debug.Log(curState.GetType().ToString() + " Enter");
        nextStateId = -1;
        curState.StateEnter();
    }
Example #3
0
    // Make sure to only change state in the late update of the state
    // So that all the updates can call first [G, C]
    public void ChangeState(string a_State)
    {
        //Debug.Log("Changing to " + a_State + " from " + currentState.m_Name);

        currentState.StateExit();
        currentState = states[a_State];
        currentState.StateEnter();
    }
Example #4
0
    public void ChangeState(State newState)
    {
        Debug.Log("changing state to " + newState.stateName);
        CurrentState.StateExit();

        CurrentState = newState;
        newState.StateEnter();
    }
Example #5
0
 public void TransitionToState(State nextState)
 {
     if (nextState != null && nextState != currentState)
     {
         currentState.StateExit(this);
         currentState = nextState;
         currentState.StateEnter(this);
     }
 }
Example #6
0
        public async Task SetState(State value)
        {
            Debug.WriteLine($"Leaving State [{_state.Name}]");
            await _state.StateLeave();

            Debug.WriteLine($"Entering State [{value.Name}]");
            await value.StateEnter();

            _state = value;
        }
Example #7
0
    public void changeState(State newState)
    {
        if (currentState != null)
        {
            currentState.StateExit();
        }

        currentState = newState;

        if (currentState != null)
        {
            currentState.StateEnter();
        }
    }
Example #8
0
    public void ChangeState(State state)
    {
        if (currentState == state)
        {
            return;
        }

        if (currentState != null)
        {
            currentState.StateExit(this.owner);
        }

        currentState = state;

        currentState.StateEnter(this.owner);
    }
Example #9
0
    /// <summary>
    /// Switch the currentState to a specific State object
    /// </summary>
    /// <param name="state">
    /// The state object to set as the currentState</param>
    /// <returns>Whether the state was changed</returns>
    public virtual bool SetState(State state, object args)
    {
        bool success = false;

        if (state && state != currentState)
        {
            State oldState = currentState;
            currentState = state;
            if (oldState)
            {
                oldState.StateExit();
            }
            currentState.StateEnter(args);
            success = true;
        }
        return(success);
    }
Example #10
0
    private void AdvanceToNextState()
    {
        if (_nextState == _currentState)
        {
            return;
        }

        Debug.Log(_nextState);

        _currentState.StateExit();

        _elapsedTime  = 0f;
        _currentState = _nextState;
        _nextState    = null;

        _currentState.StateEnter();
        ApplyEffects();
    }
Example #11
0
    //Switches the current state to a specific state object
    public virtual bool SetState(State NewState)
    {
        bool Success = false;

        //Switch to the new state if its valid and its not already the current state
        if (NewState && NewState != CurrentState)
        {
            State OldState = CurrentState;
            CurrentState = NewState;
            if (OldState)
            {
                OldState.StateExit();
            }
            CurrentState.StateEnter();
            Success = true;
        }

        return(Success);
    }
Example #12
0
    private void AdvanceToNextState()
    {
        if (_nextState == _currentState) return;

        Debug.Log(_nextState);

        _currentState.StateExit();

        _elapsedTime = 0f;
        _currentState = _nextState;
        _nextState = null;

        _currentState.StateEnter();
        ApplyEffects();
    }
Example #13
0
 protected void SetFirstState(int firstStateIndex)
 {
     _currentState = States[firstStateIndex];
     _currentState.StateEnter();
     ApplyEffects();
 }
Example #14
0
 public void Initialize(State startingState)
 {
     CurrentState = startingState;
     startingState.StateEnter();
 }
Example #15
0
 protected void SetFirstState(int firstStateIndex)
 {
     _currentState = States[firstStateIndex];
     _currentState.StateEnter();
     ApplyEffects();
 }