unity mecanim 教程能不能获得当前clip的进度

Unity3D中通过Animator动画状态机获取任意animation clip的准确播放持续时长
时间: 22:51:21
&&&& 阅读:55
&&&& 评论:
&&&& 收藏:0
标签:&&&&&&&&&&&&&&&&&&&&&&&&&&&
Unity3d 4及之前的版本中动画的播放用的animation,可直接获取其播放持续长度。但5.x及以后的版本中都是用animator来播放动画了。
While Mecanim is recommended for use in most situations, Unity has retained its legacy animation system which existed before Unity 4. You may need to use when working with older content created before Unity 4. For information on the Legacy animation system, see this section
关于在animator下如何获取其播放持续时长,很多人用的 GetCurrentAnimatorStateInfo 及 GetNextAnimatorStateInfo 等,但这个都不是最终核实的解决方案。
如下才是通过Animator动画状态机获取任意animation clip的准确播放持续时长的正确的、准确的姿势:
///获取动画状态机animator的动画clip的播放持续时长
///@MarsZ 日20:46:20
///site:www.u3dnotes.com
public static class AnimatorExt
public static float GetClipLength(this Animator animator,string clip)
if(null== animator || string.IsNullOrEmpty(clip) || null== animator.runtimeAnimatorController)
RuntimeAnimatorController ac = animator.runtimeAnimatorC
AnimationClip[] tAnimationClips =
ac.animationC
if( null == tAnimationClips || tAnimationClips.Length &= 0) return 0;
AnimationClip
tAnimationC
for (int tCounter = 0 ,tLen = tAnimationClips.L tCounter & tL tCounter ++)
tAnimationClip = ac.animationClips[i];
if(null != tAnimationClip && tAnimationClip.name == clip)
return tAnimationClip.L
return 0F;
Ref: 1、 2、 3、 (原创首发地址,转载请保留)标签:&&&&&&&&&&&&&&&&&&&&&&&&&&&原文:http://www.cnblogs.com/marsz/p/8067706.html
教程昨日排行
&&国之画&&&& &&&&&&
&& &&&&&&&&&&&&&&
鲁ICP备号-4
打开技术之扣,分享程序人生!他的最新文章
他的热门文章
您举报文章:
举报原因:
原文地址:
原因补充:
(最多只允许输入30个字)关于Mecanim中动画转换所需时间的疑问【unity3d吧】_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:81,231贴子:
关于Mecanim中动画转换所需时间的疑问收藏
anim.ResetTrigger (&Dead&);var stateInfo = anim.GetCurrentAnimatorStateInfo (0);Debug.Log (stateInfo.nameHash);var clip = anim.GetCurrentAnimationClipState (0);Debug.Log (clip[0].clip.name);if(stateInfo.nameHash == Animator.StringToHash (&Base Layer.Enemy_Large_Explode&)){
if(stateInfo.normalizedTime &= 1)
Destroy(gameObject);}想要在爆炸动画播放完成后销毁物体。在设置动画转换触发条件后,紧接着获取动画状态时,动画状态还没有切换,得到的还是Idle状态。这样就没法判断爆炸动画是否播放完成。应该怎么办呢?
自顶 求解答
登录百度帐号推荐应用他的最新文章
他的热门文章
您举报文章:
举报原因:
原文地址:
原因补充:
(最多只允许输入30个字)

我要回帖

更多关于 unity mecanim event 的文章

 

随机推荐