Ejemplo n.º 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 );
        }
Ejemplo n.º 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 );
        }
Ejemplo n.º 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 );
        }
Ejemplo n.º 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;
        }