赞
踩
Unity组件里面的Animation是可以控制播放速度的,通过调整AnimationState的speed属性即可更改某个动画的速度。
在实际需求中,可以通过改变动画速度来更快地打开一个奖励或者过场等等,这样可以让用户减少等待时间,提升体验感。
官方也给出了相关的控制接口
https://docs.unity3d.com/ScriptReference/Animation.html
speed=1为缺省速度,大于1为加速,可以按照实际来改变速度。
- anim = GetComponent<Animation>();
- foreach (AnimationState state in anim)
- {
- state.speed = 0.5F;
- }
或者控制某个单独的
- public void SetAnimationSpeed(Animation ani, string name, float speed)
- {
- if (null == ani) return;
- AnimationState state = ani[name];
- if (!state) state.speed = speed;
- }
修改Animator的播放速度会影响整个状态机的速度
- public void SetAnimatorSpeed(Animator animator, float speed)
- {
- if (null == animator) return;
- animator.speed = speed;
- }
一般不要这样改,直接改clip的速度,或者改状态机中state的速度
在lua中写这样的接口:
注意到,获取AnimationState的属性
提供了一个get属性的this字段,利用这个字段可以改变速度:
- function SetAnimationSpeed(animation, name, speed)
- if animation == nil then return end
- local state = animation.this:get(name)
- if state then state.speed = speed end
- end
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。