コード例 #1
0
 public void DeleteTransition(SoldierTransition transition)
 {
     if (!m_Map.ContainsKey(transition))
     {
         Debug.LogError("删除转换条件失败,不存在该条件 : " + transition.ToString()); return;
     }
     m_Map.Remove(transition);
 }
コード例 #2
0
 /// <summary>
 /// 根据指定的转换条件获取状态ID
 /// </summary>
 /// <param name="transition"></param>
 /// <returns></returns>
 public SoldierStateID GetOutPutState(SoldierTransition transition)
 {
     if (!m_Map.ContainsKey(transition))
     {
         Debug.LogError("获取转换条件失败,不存在该条件 : " + transition.ToString());
         return(SoldierStateID.NullState);
     }
     return(m_Map[transition]);
 }
コード例 #3
0
    public void DeleteTransition(SoldierTransition trans)
    {
        // Check for NullTransition
        if (trans == SoldierTransition.NullTransition)
        {
            Debug.LogError("SoldierFSMState ERROR: NullTransition is not allowed");
            return;
        }

        // Check if the pair is inside the map before deleting
        if (map.ContainsKey(trans))
        {
            map.Remove(trans);
            return;
        }
        Debug.LogError("SoldierFSMState ERROR: Transition " + trans.ToString() + " passed to " + stateID.ToString() +
                       " was not on the state's transition list");
    }
コード例 #4
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(SoldierTransition trans)
    {
        // Check for NullTransition before changing the current state
        if (trans == SoldierTransition.NullTransition)
        {
            Debug.LogError("SoldierFSM ERROR: NullTransition is not allowed for a real transition");
            return;
        }

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

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

        // Update the currentStateID and currentState
        currentStateID = id;
        foreach (SoldierFSMState 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()
コード例 #5
0
    public void AddTransition(SoldierTransition trans, SoldierStateID id)
    {
        // Check if anyone of the args is invalid
        if (trans == SoldierTransition.NullTransition)
        {
            Debug.LogError("SoldierFSMState ERROR: NullTransition is not allowed for a real transition");
            return;
        }

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

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

        map.Add(trans, id);
    }