Пример #1
0
 protected bool SetDefaultInitState(FSM_State newState)
 {
     // determine whether state id is valid or not
     if (newState.GetID() == StateID_Invalid)
     {
         Debug.LogError("Invalid state ID");
         return(false);
     }
     _defaultInitState = newState;
     return(true);
 }
Пример #2
0
        public bool AddState(FSM_State newState)
        {
            int stateID = newState.GetID();

            // determine whether state id is valid or not
            if (this.StateMap.ContainsKey(stateID))
            {
                Debug.LogError("StateID is repeated.");
                return(false);
            }

            this.StateMap.Add(stateID, newState);

            // this state is InitState if it's the first one
            if (this.StateMap.Count == 1)
            {
                SetDefaultInitState(newState);
            }
            return(true);
        }
Пример #3
0
        public bool ChangeState(FSM_State nextState)
        {
            // determine whether state id is valid or not
            if ((nextState == null) || (nextState.GetID() == FSM.StateID_Invalid))
            {
                Debug.LogError("Invalid state ID");
                return(false);
            }

            // compared with state priority
            if (this._stateID_Next != FSM.StateID_Invalid)
            {
                if (_thisFSM.GetState(this._stateID_Next).GetPriority() > nextState.GetPriority())
                {
                    return(true);
                }
            }
            _stateID_Next = nextState.GetID();

            return(true);
        }
Пример #4
0
        public void StateUpdate()
        {
            this._thisFSM.PreUpdate(this);

            _stateTime += Time.deltaTime;
            ++_stateCounter_Frame;

            if (this._stateID_Next != FSM.StateID_Invalid)
            {
                // do change state

                // do Leave
                _currentState.Leave(_thisFSM, this);

                // change state
                this._stateID_Prev = this._stateID_Curr;

                this._stateID_Curr = this._stateID_Next;
                this._currentState = _thisFSM.GetState(this._stateID_Next);

                this._stateID_Next = FSM.StateID_Invalid;

                // reset property
                this._stateTime           = 0.0f;
                this._stateCounter_Frame  = 1;
                this._stateCounter_Repeat = (this._stateID_Curr == this._stateID_Prev) ? this._stateCounter_Repeat + 1 : 1;

                // do Enter
                this._currentState.Enter(_thisFSM, this);
            }

            // do state update
            this._currentState.Update(_thisFSM, this);

            this._thisFSM.PostUpdate(this);
        }
Пример #5
0
 public void SetCurrentState(FSM_State FSMState)
 {
     _currentState = FSMState;
 }