コード例 #1
0
    public void DeleteTransition(FSMTransition trans)
    {
        // Check for NullTransition
        if (trans == null)
        {
            Debug.LogError("FSMState ERROR: NullTransition is not allowed");
            return;
        }

        // Check if the pair is inside the map before deleting
        if (Transitions.Contains(trans))
        {
            Transitions.Remove(trans);
            return;
        }
        Debug.LogError("FSMState ERROR: Transition " + trans.ToString() + " passed to " + StateId.ToString() +
                       " was not on the state's transition list");
    }
コード例 #2
0
        // -----------------------------------------------------------------------------------
        //
        // -----------------------------------------------------------------------------------
        public void PerformTransition(FSMTransition trans)
        {
            // Check for NullTransition before changing the current state
            if (trans == FSMTransition.NullTransition)
            {
                Debug.LogError("FSM ERROR: NullTransition is not allowed for a real transition");
                return;
            }

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

            if (id == FSMStateID.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.state == 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;
                }
            }
        }
コード例 #3
0
    public void AddTransition(FSMTransition trans)
    {
        if (trans.TargetState == null)
        {
            Debug.LogError("FSMState ERROR: target state null is not allowed");
            return;
        }

        // Since this is a Deterministic FSM,
        // check if the current transition was already inside the map
        if (Transitions.Contains(trans))
        {
            Debug.LogError("FSMState ERROR: State " + StateId.ToString() + " already has transition " + trans.ToString() +
                           "Impossible to assign to another state");
            return;
        }

        Transitions.Add(trans);
    }
コード例 #4
0
        // -----------------------------------------------------------------------------------
        //
        // -----------------------------------------------------------------------------------
        public void AddTransition(FSMTransition trans, FSMStateID id)
        {
            // Check if anyone of the args is invalid
            if (trans == FSMTransition.NullTransition)
            {
                Debug.LogError("FSMState ERROR: NullTransition is not allowed for a real FSMTransition");
                return;
            }

            if (id == FSMStateID.NullStateID)
            {
                Debug.LogError("FSMState ERROR: NullStateID is not allowed for a real ID");
                return;
            }

            // Since this is a Deterministic FSM,
            //   check if the current FSMTransition was already inside the map
            if (map.ContainsKey(trans))
            {
                Debug.LogError("FSMState ERROR: State " + FSMStateID.ToString() + " already has FSMTransition " + trans.ToString() +
                               "Impossible to assign to another state");
                return;
            }

            map.Add(trans, id);
        }