Ejemplo n.º 1
0
        /// <summary>
        /// Changes the state to the given one.
        /// </summary>
        /// <param name="state">The state to change to.</param>
        /// <param name="stateFrame">What frame to start the state at.</param>
        /// <param name="callOnInterrupt">If OnInterrupt of the current state should be called.</param>
        /// <returns></returns>
        public virtual bool ChangeState(int state, uint stateFrame = 0, bool callOnInterrupt = true)
        {
            if (states.ContainsKey(state))
            {
                EntityState oldState      = currentState;
                uint        oldStateFrame = currentStateFrame;

                if (callOnInterrupt)
                {
                    if (currentState != null)
                    {
                        currentState.OnInterrupted();
                    }
                }
                currentStateFrame = stateFrame;
                currentState      = states[state];
                OnStatePreChange?.Invoke(manager, oldState, oldStateFrame);
                if (currentStateFrame == 0)
                {
                    currentState.Initialize();
                    currentStateFrame = 1;
                }
                currentStateName = currentState.GetName();
                OnStatePostChange?.Invoke(manager, oldState, oldStateFrame);
                return(true);
            }
            return(false);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Changes the state to the given one.
        /// </summary>
        /// <param name="state">The state to change to.</param>
        /// <param name="stateFrame">What frame to start the state at.</param>
        /// <param name="callOnInterrupt">If OnInterrupt of the current state should be called.</param>
        public virtual void ChangeState(EntityState state, uint stateFrame = 0, bool callOnInterrupt = true)
        {
            EntityState oldState      = currentState;
            uint        oldStateFrame = currentStateFrame;

            if (callOnInterrupt)
            {
                currentState.OnInterrupted();
            }
            currentStateFrame = stateFrame;
            currentState      = state;
            state.Manager     = manager;
            OnStatePreChange?.Invoke(manager, oldState, oldStateFrame);
            if (currentStateFrame == 0)
            {
                currentState.Initialize();
                currentStateFrame = 1;
            }
            currentStateName = currentState.GetName();
            OnStatePostChange?.Invoke(manager, oldState, oldStateFrame);
        }