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
mecanimcontrol [2014/02/23 17:14]
Mistermind
mecanimcontrol [2018/09/17 10:29] (current)
Mistermind [Public Variables]
Line 6: Line 6:
 **Mecanim Control** is a coding tool made that allow for a wider variety of common methods used by the [[http://docs.unity3d.com/Documentation/ScriptReference/Animation.html|Animation component]] with Mecanim (Humanoid/Generic) animations. It allows you to not only dynamically load any animation clip during runtime, but also tap into several methods currently missing in this magnificent system. **Mecanim Control** is a coding tool made that allow for a wider variety of common methods used by the [[http://docs.unity3d.com/Documentation/ScriptReference/Animation.html|Animation component]] with Mecanim (Humanoid/Generic) animations. It allows you to not only dynamically load any animation clip during runtime, but also tap into several methods currently missing in this magnificent system.
  
-[[http://forum.unity3d.com/threads/224315-Mecanim-Control|Mecanim Control]] is a sub-tool of [[http://forum.unity3d.com/threads/218123-RELEASED-Universal-Fighting-Engine-(UFE)|Universal Fighting Engine]]. 
  
 ---- ----
  
 ==== 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 53:
   * [[#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 62:
 **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 75:
 **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 120:
  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 174:
   * [[#getcurrentanimationdata|GetCurrentAnimationData]]   * [[#getcurrentanimationdata|GetCurrentAnimationData]]
   * [[#getcurrentclipname|GetCurrentClipName]]   * [[#getcurrentclipname|GetCurrentClipName]]
 +  * [[#getcurrentclipplaycount|GetCurrentClipPlayCount]]
   * [[#getcurrentclipposition|GetCurrentClipPosition]]   * [[#getcurrentclipposition|GetCurrentClipPosition]]
   * [[#getmirror|GetMirror]]   * [[#getmirror|GetMirror]]
Line 168: Line 197:
 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 225:
 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 256:
 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 313:
  
 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 332:
  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 371:
 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 432:
 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 566:
 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.1393193679.txt.gz · Last modified: 2014/02/23 17:14 by Mistermind