User Tools

Site Tools


mecanimcontrol

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
mecanimcontrol [2014/02/23 17:14]
Mistermind
mecanimcontrol [2018/08/28 06:16]
Mistermind [Mecanim Control]
Line 11: Line 11:
  
 ==== Overview ==== ==== Overview ====
 +
 +{{ :mecanimcontrol2ss.jpg |}}
 +
 You can use MecanimControl much like you would use the animation component.\\ You can use MecanimControl much like you would use the animation component.\\
 To play a simple animation use //MecanimControl.Play//\\ To play a simple animation use //MecanimControl.Play//\\
 To cross-fade between animations use //MecanimControl.CrossFade// -or- one of the //MecanimControl.Play// alternatives.\\ To cross-fade between animations use //MecanimControl.CrossFade// -or- one of the //MecanimControl.Play// alternatives.\\
-To change how animations wrap (Loop, Once, PingPong) change the WrapMode of the respective AnimationClips in their import settings, or use //MecanimControl.SetWrapMode// to change it at runtime.\\+To change how animations wrap (Loop, Once, PingPong) change the WrapMode of the respective //AnimationClip// in their import settings, or use //MecanimControl.SetWrapMode// to change it at runtime.\\
 //AnimationData// can be used to modify the clip, playback speed, and direct control over blending. //AnimationData// can be used to modify the clip, playback speed, and direct control over blending.
  
Line 51: Line 54:
   * [[#debugmode|Debug Mode]]   * [[#debugmode|Debug Mode]]
   * [[#alwaysplay|Always Play]]   * [[#alwaysplay|Always Play]]
 +  * [[#overriderootmotion|Override Root Motion]]
   * [[#defaulttransitionduration|Default Transition Duration]]   * [[#defaulttransitionduration|Default Transition Duration]]
   * [[#defaultwrapmode|Default Wrap Mode]]   * [[#defaultwrapmode|Default Wrap Mode]]
Line 59: Line 63:
 **Default Animation**\\ **Default Animation**\\
 AnimationData //defaultAnimation//;\\ AnimationData //defaultAnimation//;\\
-By default, if no order is given, the animator will play the animation stored in this AnimationData.+By default, if no order is given, the animator will play the animation stored in this AnimationData. If you don't assign an animation, Mecanim Control will instantiate the first animation listed on [[#animations|animations]].
  
 <code c#> <code c#>
Line 72: Line 76:
 **Animations**\\ **Animations**\\
 AnimationData[] //animations//;\\ AnimationData[] //animations//;\\
-The array containing all the AnimationData stored by either the UI or by using AddClip.+ 
 +**Properties**\\ 
 +AnimationClip clip - The AnimationClip file.\\ 
 +string clipName - Animation name.\\ 
 +float speed - Animation speed.\\ 
 +float transitionDuration - Blending Duration.\\ 
 +WrapMode wrapMode - The animation's default [[http://docs.unity3d.com/ScriptReference/WrapMode.html|WrapMode]]. 
 +bool applyRootMotion - If this and //Override Root Motion// is toggled this animation will toggle the Animator's [[http://docs.unity3d.com/Manual/RootMotion.html|Root Motion]] 
 + 
 +**Description**\\ 
 +This array contain all the AnimationData stored by either the UI or by using AddClip. Its then used to emulate a state machine under the //Animator Controller//.
  
 <code c#> <code c#>
Line 107: Line 121:
  mecanimControl = gameObject.GetComponent<MecanimControl>();  mecanimControl = gameObject.GetComponent<MecanimControl>();
  mecanimControl.alwaysPlay = true;  mecanimControl.alwaysPlay = true;
 +}
 +</code>
 +
 +----
 +{{anchor:overriderootmotion}}
 +**Override Root Motion**\\
 +bool //overrideRootMotion//;\\
 +If both applyRootMotion (under the animation element) and this variable is //true//, this animation will toggle the Animator's [[http://docs.unity3d.com/Manual/RootMotion.html|Root Motion]].
 +
 +
 +<code c#>
 +void Start () {
 + mecanimControl = gameObject.GetComponent<MecanimControl>();
 + mecanimControl.overrideRootMotion = true;
 + mecanimControl.animationData[0].applyRootMotion = true;
 } }
 </code> </code>
Line 146: Line 175:
   * [[#getcurrentanimationdata|GetCurrentAnimationData]]   * [[#getcurrentanimationdata|GetCurrentAnimationData]]
   * [[#getcurrentclipname|GetCurrentClipName]]   * [[#getcurrentclipname|GetCurrentClipName]]
 +  * [[#getcurrentclipplaycount|GetCurrentClipPlayCount]]
   * [[#getcurrentclipposition|GetCurrentClipPosition]]   * [[#getcurrentclipposition|GetCurrentClipPosition]]
   * [[#getmirror|GetMirror]]   * [[#getmirror|GetMirror]]
Line 168: Line 198:
 void //AddClip(AnimationClip clip, string name);//\\ void //AddClip(AnimationClip clip, string name);//\\
 void //AddClip(AnimationClip clip, string name, float speed, WrapMode wrapMode)//; void //AddClip(AnimationClip clip, string name, float speed, WrapMode wrapMode)//;
 +
 +**Parameters**\\
 +clip - The AnimationClip file.\\
 +name - Animation name.\\
 +speed - Animation speed.\\
 +wrapMode - The animation's default [[http://docs.unity3d.com/ScriptReference/WrapMode.html|WrapMode]].
  
 **Description:** **Description:**
Line 190: Line 226:
 void //CrossFade(string clipName, float blendingTime);//\\ void //CrossFade(string clipName, float blendingTime);//\\
 void //CrossFade(string clipName, float blendingTime, float normalizedTime, bool mirror);//\\ void //CrossFade(string clipName, float blendingTime, float normalizedTime, bool mirror);//\\
 +void //CrossFade(AnimationData animationData, float blendingTime, float normalizedTime, bool mirror);//\\
 +
 +**Parameters**\\
 +clipName - Animation name.\\
 +animationData - The correspondent animation data.\\
 +blendingTime - The blending duration between the 2 animations.\\
 +normalizedTime - The timeline's position of the animation to be played (0-1)\\
 +mirror - Should the animation be mirrored?
  
 **Description:** **Description:**
Line 213: Line 257:
 AnimationData //GetAnimationData(AnimationClip clip);//\\ AnimationData //GetAnimationData(AnimationClip clip);//\\
 AnimationData //GetAnimationData(string clipName);//\\ AnimationData //GetAnimationData(string clipName);//\\
 +
 +**Parameters**\\
 +clip - Animation clip.\\
 +clipName - Clip name.
  
 **Description:** **Description:**
Line 266: Line 314:
  
 public class Example : MonoBehaviour { public class Example : MonoBehaviour {
- public AnimationClip walkClip; 
  void Start () {  void Start () {
  mecanimControl = gameObject.GetComponent<MecanimControl>();  mecanimControl = gameObject.GetComponent<MecanimControl>();
Line 286: Line 333:
  mecanimControl = gameObject.GetComponent<MecanimControl>();  mecanimControl = gameObject.GetComponent<MecanimControl>();
  Debug("Animation Progress (%):"+ mecanimControl.GetCurrentClipPosition() * 100);  Debug("Animation Progress (%):"+ mecanimControl.GetCurrentClipPosition() * 100);
 +}
 +</code>
 +
 +----
 +{{anchor:getcurrentclipplaycount}}
 +**GetCurrentClipPlayCount**\\
 +int //GetCurrentClipPlayCount();//\\
 +
 +**Description:**
 +Get the number of times the current clip has played. Only works if the animation's WrapMode is set to either //WrapMode.Loop// or //WrapMode.PingPong//
 +
 +<code c#>
 +void CheckProgress() {
 + mecanimControl = gameObject.GetComponent<MecanimControl>();
 + Debug("Times Played:"+ mecanimControl.GetCurrentClipPlayCount());
 } }
 </code> </code>
Line 310: Line 372:
 float //GetSpeed(AnimationClip clip);//\\ float //GetSpeed(AnimationClip clip);//\\
 float //GetSpeed(string clipName);//\\ float //GetSpeed(string clipName);//\\
 +
 +**Parameters**\\
 +clip - Animation clip.\\
 +clipName - Clip name.\\
  
 **Description:** **Description:**
Line 367: Line 433:
 void //Play(string clipName, float blendingTime, float normalizedTime, bool mirror);//\\ void //Play(string clipName, float blendingTime, float normalizedTime, bool mirror);//\\
 void //Play(AnimationClip clip, float blendingTime, float normalizedTime, bool mirror);//\\ void //Play(AnimationClip clip, float blendingTime, float normalizedTime, bool mirror);//\\
 +
 +**Parameters**\\
 +clip - Animation clip.\\
 +clipName - Animation name.\\
 +animationData - The correspondent animation data.\\
 +blendingTime - The blending duration between the 2 animations.\\
 +normalizedTime - The timeline's position of the animation to be played (0-1)\\
 +mirror - Should the animation be mirrored?
  
 **Description:** **Description:**
Line 493: Line 567:
 void //SetMirror(bool mirror);//\\ void //SetMirror(bool mirror);//\\
 void //SetMirror(bool mirror, float blendingTime);//\\ void //SetMirror(bool mirror, float blendingTime);//\\
 +void //SetMirror(bool mirror, float blendingTime, bool forceMirror);//\\
  
 **Description:** **Description:**
mecanimcontrol.txt · Last modified: 2018/09/17 10:29 by Mistermind