Unity3d 4 and previous versions of the animated play with the animation, can be directly obtained its playback duration length. But the 5.x and later versions use animator to play the animation.
Https://docs.unity3d.com/Manual/AnimationOverview.html
While Mecanim are recommended for use with most situations, Unity have retained its legacy animation system which existed befo Re Unity 4. Need to use when working with older content created before Unity 4. For information on the Legacy animation system.
about how to get their playback duration under animator, a lot of people use getcurrentanimatorstateinfo and getnextanimatorstateinfo, but this is not the final verification solution.
The following is the correct, accurate posture for capturing the exact duration of any animation clip through the Animator Animation state machine:
//Get animation state machine animator Play duration//@MarsZ December 19, 2017 20:46:20///site: Www.u3dnotes.compublic Static class Animatorext {public static float getcliplength (this Animator animator,string clip) {i F (null== Animator | | | string. IsNullOrEmpty (clip) | | null== Animator.runtimeanimatorcontroller) return 0; Runtimeanimatorcontroller ac = Animator.runtimeanimatorcontroller; animationclip[] tanimationclips = ac.animationclips;if (Null = = Tanimationclips | | tanimationclips.length <= 0) return 0; Animationclip tanimationclip; for (int tcounter = 0, tLen = tanimationclips.length; tcounter < TLen; Tcounter + +) {TA Nimationclip = Ac.animationclips[i];if (null! = Tanimationclip && tanimationclip.name = = clip) return Tanimationclip.length;} return 0F;}}
REF:
1, https://docs.unity3d.com/ScriptReference/Animator.html
2, https://docs.unity3d.com/ScriptReference/RuntimeAnimatorController.html
3, http://www.u3dnotes.com/archives/1131 (original initial address, reproduced please retain)
Unity3d the accurate playback duration of any animation clip by animator Animation state machine