コード例 #1
0
        public void SetStartState(TEnum startStateId)
        {
            BState <TEnum> startState = this.StateFromId(startStateId);

            _currentState         = startState;
            _remainingTimeInState = _currentState.GenerateTime();
        }
コード例 #2
0
        // PRAGMA MARK - INTERFACE
        public void AddTransition(TEnum stateIdFrom, TEnum stateIdTo, int weight)
        {
            BState <TEnum> stateFrom = this.StateFromId(stateIdFrom);
            BState <TEnum> stateTo   = this.StateFromId(stateIdTo);

            BStateTransition <TEnum> newTransition = new BStateTransition <TEnum>(stateTo, weight);

            stateFrom.AddTransition(newTransition);
        }
コード例 #3
0
        protected void TransitionToState(BState <TEnum> nextState)
        {
            if (nextState == null)
            {
                Debug.LogError("BasicFiniteStateMachine::TransitionToState - called with invalid state!");
                return;
            }

            // Delegate handling
            this.CallActionForMethod(_currentState.ExitKey());
            this.CallActionForMethod(_currentState.TransitionToNextStateKey(nextState));
            this.CallActionForMethod(nextState.EnterKey());

            _currentState         = nextState;
            _remainingTimeInState = _currentState.GenerateTime();
        }
コード例 #4
0
        protected void InitializeState(BState <TEnum> state, TEnum[] allEnumValues)
        {
            foreach (TEnum e in allEnumValues)
            {
                if (state.Id.Equals(e))
                {
                    continue;
                }

                this.SetupActionForMethod(state.TransitionToNextStateIdKey(e));
            }

            this.SetupActionForMethod(state.EnterKey());
            this.SetupActionForMethod(state.TickKey());
            this.SetupActionForMethod(state.FixedTickKey());
            this.SetupActionForMethod(state.ExitKey());
        }
コード例 #5
0
        protected virtual void Awake()
        {
            if (!typeof(TEnum).IsEnum)
            {
                Debug.LogError("BasicFiniteStateMachine::() - TEnum generic constraint not satisfied!");
            }

            _stateHash        = new Dictionary <TEnum, BState <TEnum> >();
            _stateActionCache = new Dictionary <string, Action>();

            // cache all of our state methods
            TEnum[] enumValues = (TEnum[])Enum.GetValues(typeof(TEnum));
            foreach (TEnum e in enumValues)
            {
                BState <TEnum> state = new BState <TEnum>(e);
                _stateHash.Add(state.Id, state);
                this.InitializeState(state, enumValues);
            }

            _remainingTimeInState = 0.0f;

            this.SetupStateMachine();
        }
コード例 #6
0
 // PRAGMA MARK - INTERFACE
 public string TransitionToNextStateKey(BState <TEnum> stateNext)
 {
     return(this.TransitionToNextStateIdKey(stateNext.Id));
 }
コード例 #7
0
        public void ForceTransitionToStateEnum(TEnum stateId)
        {
            BState <TEnum> state = this.StateFromId(stateId);

            this.TransitionToState(state);
        }
コード例 #8
0
        public void AdvanceCurrentState()
        {
            BState <TEnum> nextState = _currentState.ChooseNextState();

            this.TransitionToState(nextState);
        }
コード例 #9
0
        public void SetMinMaxTime(TEnum stateId, float min, float max)
        {
            BState <TEnum> state = this.StateFromId(stateId);

            state.SetMinMaxTime(min, max);
        }
コード例 #10
0
 public BStateTransition(BState <TEnum> destinationState, int weight)
 {
     _destinationState = destinationState;
     _weight           = weight;
 }