Exemplo n.º 1
0
    /// <summary>
    /// This method tries to change the state the FSMT1 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(FlockTransitionT1 transT1)
    {
        // Check for NullTransition before changing the current state
        if (transT1 == FlockTransitionT1.None)
        {
            Debug.LogError("FSMT1 ERROR: Null transition is not allowed");
            return;
        }

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

        if (id == FlockFSMStateT1ID.None)
        {
            Debug.LogError("FSMT1 ERROR: Current State does not have a target state for this transition");
            return;
        }

        // Update the currentStateID and currentState
        currentStateID = id;
        foreach (FlockFSMStateT1 state in fsmStates)
        {
            if (state.ID == currentStateID)
            {
                currentState = state;
                break;
            }
        }
    }
Exemplo n.º 2
0
    /// <summary>
    /// This method deletes a pair transition-state from this state´s map.
    /// If the transition was not inside the state´s map, an ERROR message is printed.
    /// </summary>
    public void DeleteTransition(FlockTransitionT1 trans)
    {
        // Check for NullTransition
        if (trans == FlockTransitionT1.None)
        {
            Debug.LogError("FSMStateT1 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("FSMStateT1 ERROR: TransitionT1 passed was not on this State´s List");
    }
Exemplo n.º 3
0
    /// <summary>
    /// This method returns the new state the FSMT1 should be if
    ///    this state receives a transition
    /// </summary>
    public FlockFSMStateT1ID GetOutputState(FlockTransitionT1 trans)
    {
        // Check for NullTransition
        if (trans == FlockTransitionT1.None)
        {
            Debug.LogError("FSMStateT1 ERROR: NullTransition is not allowed");
            return(FlockFSMStateT1ID.None);
        }

        // Check if the map has this transition
        if (map.ContainsKey(trans))
        {
            return(map[trans]);
        }

        Debug.LogError("FSMStateT1 ERROR: " + trans + " TransitionT1 passed to the State was not on the list");
        return(FlockFSMStateT1ID.None);
    }
Exemplo n.º 4
0
    public void AddTransition(FlockTransitionT1 transition, FlockFSMStateT1ID id)
    {
        // Check if anyone of the args is invallid
        if (transition == FlockTransitionT1.None || id == FlockFSMStateT1ID.None)
        {
            Debug.LogWarning("FSMStateT1 : Null transition not allowed");
            return;
        }

        //Since this is a Deterministc FSMT1,
        //Check if the current transition was already inside the map
        if (map.ContainsKey(transition))
        {
            Debug.LogWarning("FSMStateT1 ERROR: transition is already inside the map");
            return;
        }

        map.Add(transition, id);
        Debug.Log("Added : " + transition + " with ID : " + id);
    }
Exemplo n.º 5
0
 public void SetTransition(FlockTransitionT1 t)
 {
     PerformTransition(t);
 }