Beispiel #1
0
        public TargetNotInRangeReason(FSM_Brain controller, Transform target,
                                      float range, GlobalStateData.FSMStateID goToState)
        {
            transition = GlobalStateData.FSMTransistion.ReachedTarget;

            this.goToState = goToState;
            m_Controller   = controller;
            m_Character    = controller.transform;
            m_Target       = target;
            m_Range        = range;
        }
Beispiel #2
0
        /// <summary>
        /// Instantiates player transform and then if it is ok to act, the current states
        /// reason and act methods are called. Further Information on these methods can be found in
        /// the FSMState class.
        /// </summary>
        void FixedUpdate()
        {
            if (OkToAct())
            {
                stateMachine.currentState.Reason();
                stateMachine.currentState.Act();
            }

            // For debug purposes so you can see an NPC's current state in the inspector.
            currentState = stateMachine.currentState.id;
        }
Beispiel #3
0
        public TargetNotInSightReason(FSM_Brain controller, Transform target,
                                      LayerMask obstacleMask, GlobalStateData.FSMStateID goToState)
        {
            transition     = GlobalStateData.FSMTransistion.TargetNotInSight;
            this.goToState = goToState;

            m_Character    = controller.transform;
            m_Target       = target;
            m_ObstacleMask = obstacleMask;
            m_Controller   = controller;
        }
Beispiel #4
0
    public State(GlobalStateData.FSMStateID stateid, List <FSMAction> actions, List <FSMReason> reasons)
    {
        this.stateID = stateid;
        this.actions = actions;
        this.reasons = reasons;

        foreach (var reason in reasons)
        {
            AddTransition(reason.Transition, reason.GoToState);
        }
    }
        public HitObstacleReason(FSM_Brain controller, MovementHandler movementHandler,
                                 LayerMask obstacleMask,
                                 GlobalStateData.FSMStateID goToState)
        {
            transition = GlobalStateData.FSMTransistion.HitObstacle;

            m_Controller   = controller;
            m_Character    = controller.transform;
            m_Handler      = movementHandler;
            m_ObstacleMask = obstacleMask;
            this.goToState = goToState;
        }
Beispiel #6
0
    public State(GlobalStateData.FSMStateID stateid, FSMAction action, List <FSMReason> reasons)
    {
        var actionList = new List <FSMAction>();

        actionList.Add(action);

        this.stateID = stateid;
        this.actions = actionList;
        this.reasons = reasons;

        foreach (var reason in reasons)
        {
            AddTransition(reason.Transition, reason.GoToState);
        }
    }
Beispiel #7
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);
    }
Beispiel #8
0
    public void DeleteState(GlobalStateData.FSMStateID stateID)
    {
        if (stateID == GlobalStateData.FSMStateID.None)
        {
            Debug.LogWarning(SCRIPT_NAME + ": no state id");
            return;
        }


        // Search the List and delete the state if it´s inside it
        foreach (FSMState state in fsmStates)
        {
            if (state.ID == stateID)
            {
                fsmStates.Remove(state);
                return;
            }
        }

        Debug.LogError(SCRIPT_NAME + ": The state passed was not on the list");
    }
Beispiel #9
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;
            }
        }
    }
Beispiel #10
0
 public State(GlobalStateData.FSMStateID stateid, List <FSMAction> actions, FSMReason reason)
     : this(stateid, actions, reason.ToList())
 {
 }
Beispiel #11
0
 public State(GlobalStateData.FSMStateID stateid, FSMAction action, List <FSMReason> reasons)
     : this(stateid, action.ToList(), reasons)
 {
 }