Пример #1
0
        public void AddState( FSMState state )
        {
            if ( state == null )
            {
                Log.Write( "Attempted to add a null FSMState to a FiniteStateMachine." );
                return;
            }

            states.Add( state );
        }
Пример #2
0
        public void Render( float moveFactor )
        {
            if ( states.Count == 0 )
                return;

            if ( currentState == null )
            {
                currentState = defaultState;
                currentState.Enter();
            }
            if ( currentState == null )
                return;

            currentState.Render( moveFactor );
        }
Пример #3
0
        public void Update( float moveFactor )
        {
            if ( states.Count == 0 )
                return;

            if ( currentState == null )
            {
                currentState = defaultState;
                currentState.Enter();
            }
            if ( currentState == null )
                return;

            int oldStateID = currentState.Type;
            goalID = currentState.CheckTransitions( moveFactor );

            if ( goalID != oldStateID )
            {
                if ( TransitionState( goalID ) )
                {
                    currentState.Exit();
                    currentState = goalState;
                    currentState.Enter();
                }
            }

            currentState.Update( moveFactor );
        }
Пример #4
0
        private bool TransitionState( int goalStateID )
        {
            foreach ( FSMState state in states )
            {
                if ( state.Type == goalStateID )
                {
                    goalState = state;
                    return true;
                }
            }

            if ( goalStateID == defaultState.Type )
                goalState = defaultState;

            return false;
        }