public void AddState( FSMState state ) { if ( state == null ) { Log.Write( "Attempted to add a null FSMState to a FiniteStateMachine." ); return; } states.Add( state ); }
public void Render( float moveFactor ) { if ( states.Count == 0 ) return; if ( currentState == null ) { currentState = defaultState; currentState.Enter(); } if ( currentState == null ) return; currentState.Render( moveFactor ); }
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 ); }
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; }