protected virtual void SwitchState(State newState)
        {
            if (_currentState != null && _currentState.GetType() == newState.GetType())
            {
                return;
            }

            _currentState?.ExitState();
            _currentState = newState;
            _currentState.InitState();
            _updateState = _currentState.UpdateState;
        }
Пример #2
0
        public void ChangeState(State <T> newState)
        {
            if (currentState != null)
            {
                currentState.Exit();
            }

            currentState = newState;
            currentState.Init(this, refScript);
            DebugMessage("Entering");
            currentState.Enter();
            DebugMessage(newState.GetType().Name);
        }
Пример #3
0
        public void ChangeState(State newState)
        {
            if (_currentState == null)
            {
                ChangeCurrentStateAndCallOnEnter(newState);
            }

            else if (_currentState.GetType() != newState.GetType())
            {
                ExitPreviousState();
                //Debug.Log(this.GetType() + " Enter newState " + newState.GetType());

                ChangeCurrentStateAndCallOnEnter(newState);
            }
        }
Пример #4
0
        /// <summary>
        /// Assign the state values from the manager
        /// </summary>
        /// <param name="currentState">The state to assign values to</param>
        public static void SetStateValues(State currentState)
        {
            if (currentState == null)
            {
                Debug.Log("Cannot set defaults to a state that is null!");
                return;
            }

            Type type = currentState.GetType();

            if (!RegisteredStates.ContainsKey(type))
            {
                Debug.Log("Cannot find state type of " + type);
                return;
            }

            List <StateFieldInfo> fields = RegisteredStates[type].fields;

            for (int i = 0; i < fields.Count; i++)
            {
                fields[i].SetValue(currentState);
            }
        }