Exemple #1
0
 public void UpdateGraph(float remaining_weight)
 {
     if( _current_transition != null && _current_transition.IsDone() ) {
         // if the current transition is finished, then jump to the destination state
         _desired_state = _current_state;
         _current_state = _current_transition.Destination;
         _current_transition = null;
     }
     if( _current_transition != null ) {
         _current_transition.UpdateGraph( remaining_weight );
     } else {
         _current_state.UpdateGraph( remaining_weight );
         if( !_current_state.IsLooping ) {
             // if the current state is not looping, change back immeditately to the previous state (don't worry the transition will know to wait for the non looping state to finish)
             ChangeState( _desired_state.name );
         }
     }
 }
Exemple #2
0
 public bool ChangeState( string name )
 {
     State next = this.GetStateByName( name );
     if( next != null ) {
         // save this state, in case you need to transition to it immediately after a non looping state
         _desired_state = next;
     }
     if( _current_transition != null ) {
         // you can't change state if you're in a transition
         return false;
     } else if( next == null ) {
         Debug.LogError( "Could not find the state: " + name.ToString() );
         return false;
     } else if( next != _current_state ) {
         // find a transition to the next state and make it if possible
         Transition t = _current_state.GetTransitionTo( next );
         if( t != null ) {
             _current_transition = t;
             _current_transition.Start( next );
             return true;
         } else {
             return false;
         }
     } else {
         return true;
     }
 }