DoBeforeEntering() public method

This method is used to set up the State condition before entering it. It is called automatically by the FSMSystem class before assigning it to the current state.
public DoBeforeEntering ( ) : void
return void
コード例 #1
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(FsmTransitionId trans)
    {
        // Check for NullTransition before changing the current state
        if (trans == FsmTransitionId.NullTransition)
        {
            throw new Exception("FSM ERROR: NullTransition is not allowed for a real transition");
        }

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

        if (id == FsmStateId.NullStateID)
        {
            throw new Exception("FSM ERROR: State " + currentStateID.ToString() + " does not have a target state " +
                                " for transition " + trans.ToString());
        }

        // 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;

                // Reset the state to its desired condition before it can reason or act
                currentState.DoBeforeEntering();
                break;
            }
        }
    }     // PerformTransition()
コード例 #2
0
 /// <summary>
 /// Call this to trigger the before action on the first state in the list
 /// </summary>
 public void Start()
 {
     currentState.DoBeforeEntering();
 }
コード例 #3
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(FsmTransitionId trans)
    {
        // Check for NullTransition before changing the current state
        if (trans == FsmTransitionId.NullTransition)
        {
            throw new Exception("FSM ERROR: NullTransition is not allowed for a real transition");
        }

        // Check if the currentState has the transition passed as argument
        FsmStateId id = currentState.GetOutputState(trans);
        if (id == FsmStateId.NullStateID)
        {
            throw new Exception("FSM ERROR: State " + currentStateID.ToString() + " does not have a target state " +
                           " for transition " + trans.ToString());
        }

        // 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;

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