Example #1
0
    /// <summary>
    /// Adds a transition, stateID pair to the transition map. Every transition called
    /// in the states Reason method should have a corresponding state id in the map.
    /// </summary>
    public void AddTransition(GlobalStateData.FSMTransistion transition, GlobalStateData.FSMStateID id)
    {
        // Ensure valid transition.
        if (transition == GlobalStateData.FSMTransistion.None || id == GlobalStateData.FSMStateID.None)
        {
            Debug.LogWarning(SCRIPT_NAME + " : Null transition not allowed");
            return;
        }

        // Ensure transition not already present in map.
        if (map.ContainsKey(transition))
        {
            Debug.LogWarning(SCRIPT_NAME + ": transition is already inside the map | " + transition);
            return;
        }

        map.Add(transition, id);
    }
Example #2
0
    /// <summary>
    /// Deletes a transition, stateID pair from the transition map.
    /// </summary>
    public void DeleteTransition(GlobalStateData.FSMTransistion transition)
    {
        // Ensures valid transition.
        if (transition == GlobalStateData.FSMTransistion.None)
        {
            Debug.LogError(SCRIPT_NAME + ": None transition is not allowed");
            return;
        }

        // Ensure map contains transition before attempting delete.
        if (map.ContainsKey(transition))
        {
            map.Remove(transition);
            return;
        }

        Debug.LogError(SCRIPT_NAME + ": transition passed was not on this StateĀ“s List | " + transition);
    }
Example #3
0
    /// <summary>
    /// This method returns the state that would be transitioned into based on the FSMTransition.
    /// </summary>
    public GlobalStateData.FSMStateID GetOutputState(GlobalStateData.FSMTransistion transition)
    {
        // Ensures valid transition.
        if (transition == GlobalStateData.FSMTransistion.None)
        {
            Debug.LogError(SCRIPT_NAME + ": None transition is not allowed");
            return(GlobalStateData.FSMStateID.None);
        }

        // Ensure map contains transition before returning new state.
        if (map.ContainsKey(transition))
        {
            return(map[transition]);
        }

        Debug.LogError(SCRIPT_NAME + ": transition passed to the State was not on the list | " + transition);

        // Transition not in map.
        return(GlobalStateData.FSMStateID.None);
    }
Example #4
0
    public void PerformTransition(GlobalStateData.FSMTransistion trans)
    {
        // Check for NullTransition before changing the current state
        if (trans == GlobalStateData.FSMTransistion.None)
        {
            Debug.LogError(SCRIPT_NAME + ": Null transition is not allowed");
            return;
        }

        // Check if the currentState has the transition passed as argument
        GlobalStateData.FSMStateID id = currentState.GetOutputState(trans);
        if (id == GlobalStateData.FSMStateID.None)
        {
            Debug.LogError(SCRIPT_NAME + ": Current State does not have a target state for this transition");
            return;
        }


        // Update the currentStateID and currentState
        //currentStateID = id;
        foreach (FSMState state in fsmStates)
        {
            if (state.ID == id)
            {
                // Store previous state and call exit method.
                previousState = currentState;
                previousState.Exit();

                // Update current state and call enter method.
                currentState = state;
                currentState.Enter();

                break;
            }
        }
    }
Example #5
0
 /// <summary>
 /// This performs a transistion from one state to another and is invoked in an individual states Reason method.
 /// </summary>
 public void SetTransistion(GlobalStateData.FSMTransistion tran)
 {
     stateMachine.PerformTransition(tran);
 }