Example #1
0
 /// <summary>
 /// Returns the current state in the specified layer
 /// </summary>
 /// <param name="layer">
 /// A <see cref="System.Int32"/>
 /// </param>
 /// <returns>
 /// A <see cref="System.String"/>
 /// </returns>
 public string GetCurrentState(int layer)
 {
     if (IsLoaded)
     {
         Mixamo.State s = this.graph.layers[layer].GetCurrentState();
         return((s == null ? "" : s.name));
     }
     else
     {
         return("");
     }
 }
Example #2
0
    void OnGUI_PerControl()
    {
        bool b = GUILayout.Toggle((RootMotionMode == AnimationStateMachine.RootMotionModeType.Automatic), new GUIContent("Extract Root Automatically"));

        RootMotionMode = (b ? AnimationStateMachine.RootMotionModeType.Automatic : AnimationStateMachine.RootMotionModeType.Manual);
        GUILayout.Label("Extracted Root Motion: " + FormatVector(extractedRootMotion));
        GUILayout.Label("Current State: " + graph.layers[0].GetCurrentState().name);
        GUILayout.BeginHorizontal();
        GUILayout.Label("Go To State: ");
        GUIContent[] guiContents = new GUIContent[graph.layers[0].states.Length];
        for (int i = 0; i < graph.layers[0].states.Length; i++)
        {
            guiContents[i] = new GUIContent(graph.layers[0].states[i].name);
        }
        int currState = inputs.selectedState;

        inputs.selectedState = GUILayout.SelectionGrid(inputs.selectedState, guiContents, 3, GUILayout.Width(200), GUILayout.ExpandHeight(true));

        if (currState != inputs.selectedState)
        {
            Mixamo.State s = graph.layers[0].states[inputs.selectedState];
            DebugLog("Go To State: " + s.name.ToString());
            DebugLog("Success: " + graph.layers[0].ChangeState(s.name.Clone().ToString()).ToString());
        }
        GUILayout.EndHorizontal();
        foreach (string name in graph.ControlParams.Names)
        {
            GUILayout.Label(name);
            graph.ControlParams[name] = GUILayout.HorizontalSlider(graph.ControlParams[name], 0f, (name.EndsWith("_speed") ? 2f : 1f), GUILayout.Width(200));
        }
        GUIStyle sty = new GUIStyle();

        sty.padding          = new RectOffset(0, 0, 0, 0);
        sty.margin           = new RectOffset(0, 0, 0, 0);
        sty.normal.textColor = Color.white;
        GUILayout.BeginVertical(sty);
        foreach (Mixamo.Clip c in this.graph.clips)
        {
            AnimationState s = c.anim_state;
            GUILayout.Label(s.name + ": " + FormatFloat(s.weight) + " : " + FormatFloat(s.speed) + " : " + FormatFloat(s.length) + " (" + c.name + ")", sty);
        }
        GUILayout.EndVertical();
    }
Example #3
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;
 }
Example #4
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 );
     }
 }
Example #5
0
 public Clip GetClipByNameAndMarkInUse( string name , State parent)
 {
     Clip c = GetClipByName(name );
     c.MarkInUse();
     c.state = parent;
     return c;
 }
Example #6
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" );
     }
 }
Example #7
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 );
            }
        }
Example #8
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 );
     }
 }
Example #9
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 );
         }
     }
 }
Example #10
0
 public Transition GetTransitionTo(State next)
 {
     foreach( Transition t in transitions ) {
         if( t.CanBeMade( next ) ) {
             return t;
         }
     }
     return null;
 }
Example #11
0
 public void Init()
 {
     _current_state = states[0];
     _desired_state = _current_state;
 }
Example #12
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;
 }
Example #13
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;
     }
 }
Example #14
0
 public override void Start(State dest)
 {
     base.Start(dest);
     t_weight = 0f;
     destination.ResetTime(0f);
 }
Example #15
0
 public CrossfadeTransition( State source , State destination , float duration , string[] guards )
 {
     this.source = source;
     this.start_destination = destination;
     this.duration = duration;
     this.guards = guards;
 }