示例#1
0
        public void PerformTransition(Transition trans)
        {
            if (trans == Transition.NullTransition)
            {
                Debug.LogError("FSM: Null transition can't be used");
                return;
            }

            StateID id = _currentState.GetOutputState(trans);

            if (id == StateID.NullStateID)
            {
                Debug.LogError("FSM: No target to transition to");
                return;
            }

            _currentStateID = id;

            foreach (FSMState state in _states)
            {
                if (state.ID == _currentStateID)
                {
                    _currentState.DoBeforeLeaving();
                    _currentState = state;
                    _currentState.DoBeforeEntering();
                    break;
                }
            }
        }
示例#2
0
        /// <summary>
        /// This method tries to change the state the FSM is in based on
        /// the current state and the transition passed. If current state
        ///  doesn't have a target state for the transition passed,
        /// an ERROR message is printed.
        /// </summary>
        public void PerformTransition(Transition trans)
        {
            // Check for NullTransition before changing the current state
            if (trans == Transition.NullTransition)
            {
                Debug.LogError("FSM ERROR: NullTransition is not allowed for a real transition");
                return;
            }

            currentTransition = trans;

            // Check if the currentState has the transition passed as argument
            StateID id = currentState.GetOutputState(trans);

            if (id == StateID.NullStateID)
            {
                Debug.LogError("FSM ERROR: State " + currentStateID.ToString() + " does not have a target state " +
                               " for transition " + trans.ToString());
                return;
            }

            // Update the currentStateID and currentState
            currentStateID = id;
            foreach (FSMState state in states)
            {
                if (state.ID == currentStateID)
                {
                    // Do the post processing of the state before setting the new one
                    currentState.DoBeforeLeaving();

                    currentState = state;

                    Debug.Log(state);

                    // Reset the state to its desired condition before it can reason or act
                    currentState.DoBeforeEntering();
                    break;
                }
            }

            currentTransition = Transition.NullTransition;
        } // PerformTransition()
示例#3
0
文件: FSM.cs 项目: clientbase/LeanFSM
        public void PerformTransition(S trans)
        {
            // Check for NullTransition before changing the current state
            if (EqualityComparer <S> .Default.Equals(trans, (S)typeof(S).GetEnumValues().GetValue(0)))
            {
                Debug.LogError("FSM ERROR: NullTransition is not allowed for a real transition");
                return;
            }

            // Check if the currentState has the transition passed as argument
            S id = currentState.GetOutputState(trans);

            if (EqualityComparer <S> .Default.Equals(id, (S)typeof(S).GetEnumValues().GetValue(0)))
            {
                Debug.LogError("FSM ERROR: State " + currentStateID.ToString() + " does not have a target state " +
                               " for transition " + trans.ToString());
                return;
            }

            // Update the currentStateID and currentState
            currentStateID = id;
            foreach (FSMState <S> state in states)
            {
                if (EqualityComparer <S> .Default.Equals(state.ID, currentStateID))
                {
                    // Do the post processing of the state before setting the new one
                    currentState.DoBeforeLeaving();

                    currentState = state;

                    // Reset the state to its desired condition before it can reason or act
                    currentState.DoBeforeEntering();
                    break;
                }
            }
        }