示例#1
0
 public ClipTransition(  Clip c , State source , State dest , float dur_in , float dur_out , string[] guards )
 {
     clip = c;
     clip.anim_state.wrapMode = WrapMode.ClampForever;
     clip.anim_state.enabled = true;
     this.source = source;
     this.start_destination = dest;
     duration_in = dur_in;
     if( duration_in == 0f ) {
         WaitTillEnd = true;
     }
     duration_out = dur_out;
     this.guards = guards;
 }
示例#2
0
 public override void Start( State dest)
 {
     base.Start(dest);
     t_weight_start = 0f;
     t_weight_end = 0f;
     clip.ResetTime(0f);
     dest.ResetTime(0f);
     if( duration_in == 0f ) {
         source.SetCurrentWrapMode( MixamoWrapMode.ClampForever );
     }
 }
示例#3
0
 public Clip GetClipByNameAndMarkInUse( string name , State parent)
 {
     Clip c = GetClipByName(name );
     c.MarkInUse();
     c.state = parent;
     return c;
 }
示例#4
0
 private TreeNode JsonToTreeNode( Hashtable json_tree  , State parent )
 {
     string str = (string) json_tree["type"];
     switch( str ) {
     case "blank":
         return( new BlankClip() );
     case "clip":
         return( this.GetClipByNameAndMarkInUse( (string) json_tree["name"] , parent) );
     case "blend2d":
         Blend2d sb = new Blend2d(JsonToTreeNode( (Hashtable) json_tree["blend1"] , parent ) , JsonToTreeNode( (Hashtable) json_tree["blend2"] , parent ) , (string) json_tree["control"] );
         sb.state = parent;
         return sb;
     /*case "list":
         ListBlend lb = new ListBlend();
         lb.control = (string) json_tree["control"];
         ArrayList json_blends = (ArrayList) json_tree["blends"];
         lb.blends = new TreeNode[json_blends.Count];
         for( int i=0;i<json_blends.Count;i++ ) {
             lb.blends[i] = JsonToTreeNode( (Hashtable) json_blends[i] );
         }
         return lb;
         break;*/
     case "additive":
         AdditiveBlend ab = new AdditiveBlend(
                                              (Clip) JsonToTreeNode( (Hashtable) json_tree["difference_clip"] , parent ) ,
                                              JsonToTreeNode( (Hashtable) json_tree["blend"], parent) ,
                                              (string) json_tree["control"],
                                              (string) json_tree["additive_control"]
                                              );
         ab.state = parent;
         return ab;
     default:
         throw new System.Exception( "Could not create" );
     }
 }
示例#5
0
        /// <summary>
        /// Returns whether or the transition can be taken to the destination state.
        /// </summary>
        /// <param name="dest">
        /// A <see cref="State"/>
        /// </param>
        /// <returns>
        /// A <see cref="System.Boolean"/>
        /// </returns>
        public virtual bool CanBeMade( State dest)
        {
            if( guards != null ) {
                foreach( string g in guards ) {
                    if( source.layer.graph.TransitionHandler != null && !source.layer.graph.TransitionHandler.CanTransitionTo( g , source.name , dest.name ) ) {
                        return false;
                    }
                }
            }

            if( start_destination == null ) {
                return true;
            } else {
                return( dest == start_destination );
            }
        }
示例#6
0
 /// <summary>
 /// Initiate the transition. Called when a transition is started from ChangeState().
 /// </summary>
 /// <param name="dest">
 /// A <see cref="State"/>
 /// </param>
 public virtual void Start(State dest)
 {
     finished = false;
     this.destination = dest;
     if( !this.destination.IsLooping ) {
         this.destination.ResetTime( 0f );
     }
 }
示例#7
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 );
         }
     }
 }
示例#8
0
 public Transition GetTransitionTo(State next)
 {
     foreach( Transition t in transitions ) {
         if( t.CanBeMade( next ) ) {
             return t;
         }
     }
     return null;
 }
示例#9
0
 public void Init()
 {
     _current_state = states[0];
     _desired_state = _current_state;
 }
示例#10
0
 public Transition CreateDefaultTransition(  State source  )
 {
     // default transition is to crossfade to every state
     Transition t = new CrossfadeTransition( source , null , 0.1f , new string[0] {} );
     return t;
 }
示例#11
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;
     }
 }
示例#12
0
 public override void Start(State dest)
 {
     base.Start(dest);
     t_weight = 0f;
     destination.ResetTime(0f);
 }
示例#13
0
 public CrossfadeTransition( State source , State destination , float duration , string[] guards )
 {
     this.source = source;
     this.start_destination = destination;
     this.duration = duration;
     this.guards = guards;
 }