Exemple #1
0
    void LateUpdate()
    {
        CurrentState.LateUpdate();

        if (string.IsNullOrEmpty(RequestedNewState) == false)
        {
            PreviousStateName = CurrentState.StateName;
            AbstractFSMState newState = States.Find(item => item.StateName == RequestedNewState);
            CurrentState.Leave(newState.MultiPanelDeclarations);
            CurrentState      = newState;
            RequestedNewState = "";
            if (OnStateEnter != null)
            {
                OnStateEnter(newState.StateName);
            }
            CurrentState.Enter(RequestedNewStateOnEnterParams);

            if (CurrentState.NeedsGUILayout)
            {
                useGUILayout = true;
            }
            else
            {
                useGUILayout = false;
            }
        }
    }
 public void EnterState(FSMStateType stateType)
 {
     if (_fsmStates.ContainsKey(stateType))
     {
         AbstractFSMState nextState = _fsmStates[stateType];
         EnterState(nextState);
     }
 }
 public virtual void Initialize(AbstractFSMState state)
 {
     if(CurrentState != null)
     {
         CurrentState.Exit();
     }
     CurrentState = state;
     CurrentState.Enter();
 }
    public void EnterState(AbstractFSMState nextState)
    {
        if (nextState == null)
        {
            return;
        }

        _currentState = nextState;
        _currentState.EnterState();
    }
Exemple #5
0
        public void EnterState(FSMStateType stateType)
        {
            if (_fsmStates.ContainsKey(stateType))
            {
                //get value in the dictionary that corresponds to that key
                AbstractFSMState nextState = _fsmStates[stateType];

                //_currentState.ExitState();

                EnterState(nextState);
            }
        }
 public virtual void ChangeState(AbstractFSMState state)
 {
     if(CurrentState != null)
     {
         CurrentState.Exit();
     }
     else
     {
         throw new System.Exception("Pass null state");
     }
     CurrentState = state;
     CurrentState.Enter();
 }
 public void ControllerInitialize(FSMSystem fsmSystem, AbstractFSMState state, AbstractPanelDeclarations primaryPanelDeclarations, bool autoGUISetActive)
 {
     AutoGUISetActive         = autoGUISetActive;
     FsmSystem                = fsmSystem;
     State                    = state;
     PrimaryPanelDeclarations = primaryPanelDeclarations;
     if (GUIPanel != null && AutoGUISetActive == true)
     {
         SetPanelActive(false);
     }
     if (PrimaryPanelDeclarations != null)
     {
         PrimaryPanelDeclarations.OnButtonClicked += this.GUIButtonEventHandler;
     }
     OnInitialize();
 }
Exemple #8
0
    /// <summary>
    /// Returns the state controller for the given state
    /// or the state controller for the current state if stateName is null
    /// </summary>
    public AbstractFSMStateController GetStateController(string stateName = null)
    {
        if (stateName == null)
        {
            stateName = CurrentStateName;
        }

        AbstractFSMState stateObject = States.Find(item => item.StateName == stateName);

        if (stateObject != null)
        {
            return(stateObject.StateController);
        }
        else
        {
            log.Error(_Logger.User.Msaw, "Cannot get state controller for state '" + stateName + "'. It doesn't exist in the state machine system. Returning null.");
        }
        return(null);
    }
Exemple #9
0
        public void Awake()
        {
            _currentState = null;

            _fsmStates = new Dictionary <FSMStateType, AbstractFSMState>();

            NavMeshAgent navMeshAgent = GetComponent <NavMeshAgent>();
            FsmEnemy     fsmEnemy     = GetComponent <FsmEnemy>();
            Transform    player       = GameObject.Find("Player").transform;

            foreach (AbstractFSMState state in _validStates)
            {
                state.SetExecutingFSM(this);
                state.SetExecutingFsmEnemy(fsmEnemy);
                state.SetNavMeshAgent(navMeshAgent);
                state.SetExecutingPlayer(player);
                _fsmStates.Add(state.StateType, state);
            }
        }
        public void Awake()
        {
            _currentState = null;

            _fsmStates = new Dictionary <FSMStateType, AbstractFSMState>();

            NavMeshAgent navMeshAgent = this.GetComponent <NavMeshAgent>();

            Assets.Scripts.FSM.Code.NPC npc = this.GetComponent <Assets.Scripts.FSM.Code.NPC>();
            //_fsmStates.Clear();
            var arrayOfAllKeys = _fsmStates.ToArray();
            int count          = 0;

            if (!_validStates.Any())
            {
                Debug.Log("EMPTY LIST");
            }
            foreach (AbstractFSMState state in _validStates)
            {
                //Debug.Log("STARTING: " + count);
                //Debug.Log("State: " + state.StateType);
                //Debug.Log("_VALIDSTATES: " + count + ": " + _validStates[count]);
                state.SetExecutingFSM(this);
                state.SetExecutingNPC(npc);
                state.SetNavMeshAgent(navMeshAgent);

                if (state.GetType() == typeof(PatrolState))
                {
                    state.StateType = FSMStateType.PATROL;
                }
                if (state.GetType() == typeof(IdleState))
                {
                    state.StateType = FSMStateType.IDLE;
                }

                if (!_fsmStates.ContainsKey(state.StateType))
                {
                    _fsmStates.Add(state.StateType, state);
                }
                count++;
            }
        }
Exemple #11
0
    public void Awake()
    {
        _currentState = null;

        _fsmStates = new Dictionary <FSMStateType, AbstractFSMState>();

        NavMeshAgent navMeshAgent = GetComponent <NavMeshAgent>();
        NPC          npc          = GetComponent <NPC>();
        Transform    player       = playerTransform;
        Renderer     material     = GetComponent <MeshRenderer>();

        foreach (var state in _validStates)
        {
            state.SetExecutingFSM(this);
            state.SetExecutingNPC(npc);
            state.SetNavMeshAgent(navMeshAgent);
            state.SetPlayerTransform(player);
            state.SetMaterial(material);
            _fsmStates.Add(state.StateType, state);
        }
    }
Exemple #12
0
        public FiniteStateMachine(Enemy enemy)
        {
            this.enemy = enemy;


            _currentState = null;

            _fsmStates = new Dictionary <FSMStateType, AbstractFSMState>();

            this._validStates = new List <AbstractFSMState>()
            {
                new IdleState(), new WalkState(), new AttackState()
            };

            foreach (AbstractFSMState state in _validStates)
            {
                state.SetExecutingFSM(this);
                state.SetExecutingNPC(enemy);
                _fsmStates.Add(state.StateType, state);

                EnterState(FSMStateType.IDLE);
            }
        }
 public void PanelInitialize(FSMSystem fsmSystem, bool autoGUISetActive, AbstractFSMState state)
 {
     AutoGUISetActive = autoGUISetActive;
     if (FsmSystem != null)
     {
         if (FsmSystem != fsmSystem)
         {
             log.Error(_Logger.User.Msaw, "Trying to register panel in more than one states that are in different FsmSystems. This is currently not tested and shouldn't be done.");
         }
     }
     FsmSystem = fsmSystem;
     if (States == null)
     {
         States = new List <AbstractFSMState>();
     }
     States.Add(state);
     State = state;
     //GUIPanel = this.GetComponent<UIPanel>();
     //if (GUIPanel != null && AutoGUISetActive == true)
     //{
     SetPanelActive(false);
     //}
     OnInitialize();
 }
 public void Awake()
 {
     _currentState = null;
 }