Ejemplo n.º 1
0
    public void PerformTransition(ZombieTransition trans)
    {
        // Check for None Transition before changing the current state
        if (trans == ZombieTransition.None)
        {
            Debug.LogError("ZombieFSM Error: None Transition is not allowed for a real transition");
            return;
        }

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

        if (id == ZombieFSMStateID.None)
        {
            Debug.LogError("ZombieFSM Error: State " + currentStateID.ToString() + " doesn't have a target state for transition " + trans.ToString());
            return;
        }

        // Update the currentState and currentStateID
        currentStateID = id;
        foreach (ZombieFSMState state in states)
        {
            if (state.ID == currentStateID)
            {
                // Do the post processing of the state before setting the new one
                currentState = state;
                // Reset the state to its desirec condition before it can reason or act
                break;
            }
        }
    }
Ejemplo n.º 2
0
    public void AddState(ZombieFSMState state)
    {
        // Check for Null Reference before Adding
        if (state == null)
        {
            Debug.LogError("ZombieFSM Error: Null reference is not allowed");
        }

        // First State inserted also the initial state, the state the machine  is in when the simulation begins
        if (states.Count == 0)
        {
            states.Add(state);
            currentState   = state;
            currentStateID = state.ID;
            return;
        }

        // Add the state to the List if it is not inside it
        foreach (ZombieFSMState s in states)
        {
            if (s.ID == state.ID)
            {
                Debug.LogError("ZombieFSM Error: Impossible to add state " + state.ID.ToString() + " because state has already been added");
                return;
            }
        }

        states.Add(state);
    }
Ejemplo n.º 3
0
    public void DeleteState(ZombieFSMStateID id)
    {
        // Check for None State before deleting
        if (id == ZombieFSMStateID.None)
        {
            Debug.LogError("ZombieFSM Error: None is not allowed for a real state");
            return;
        }

        // Search the list and delete the state if it's inside it
        foreach (ZombieFSMState state in states)
        {
            if (state.ID == id)
            {
                states.Remove(state);
                return;
            }
        }

        Debug.LogError("ZombieFSM Error: Impossible to delete state " + id.ToString() + ". It was not on the list of states");
    }
Ejemplo n.º 4
0
//    protected float curRotSpeed;
//    protected float curSpeed;
//    protected Vector3 desPos;

    public void AddTransition(ZombieTransition trans, ZombieFSMStateID id)
    {
        // Check if anyone of the args is invalid
        if (trans == ZombieTransition.None)
        {
            Debug.LogError("ZombieFSMState Error: None is not allowed for a real Transition");
            return;
        }

        if (id == ZombieFSMStateID.None)
        {
            Debug.LogError("ZombieFSMState Error: None is not allowed for a real ID");
            return;
        }

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

        map.Add(trans, id);
    }