当前位置:网站首页>Slider controls the playback progress of animator animation
Slider controls the playback progress of animator animation
2022-06-24 21:34:00 【Nangongming】
Preface
In some application scenarios, you may need to use Slider Control the playback progress of animation , What click , Drag , Search and find that you are using Animation, After all, there are API It is quite convenient to call , can Animation It's an old version , Today, let's talk about how to control Animator Animation , The code is simple
Code
public class UISlider :MonoBehaviour, IBeginDragHandler, IEndDragHandler, IDragHandler, IPointerDownHandler
{
bool drag = false;
public Animator Animator;
AnimatorStateInfo animatorStateInfo;
public Slider component
public void SetAnimTarget(Animator target)
{
Animator = target;
}
private void OnEnable()
{
component.value = 0;
drag = false;
}
private void Update()
{
if (!drag)
{
if (Animator)
{
// Get the current animation clip information
animatorStateInfo = Animator.GetCurrentAnimatorStateInfo(0);
//normalizedTime It's a 0-1 Value Representative progress
component.value = animatorStateInfo.normalizedTime;
}
else
{
Hide();
}
}
}
public void OnBeginDrag(PointerEventData eventData)
{
drag = true;
}
public void OnEndDrag(PointerEventData eventData)
{
drag = false;
}
public void UpdateAuto_Anim(float normalizedTime)
{
animatorStateInfo = Animator.GetCurrentAnimatorStateInfo(0);
// Play from the specified progress
Animator.Play(animatorStateInfo.fullPathHash, 0, normalizedTime);
}
public void OnDrag(PointerEventData eventData)
{
drag = true;
UpdateAuto_Anim(component.value);
}
public void OnPointerDown(PointerEventData eventData)
{
UpdateAuto_Anim(component.value);
}
}
边栏推荐
- HCIA assessment
- Memcached comprehensive analysis – 3 Deletion mechanism and development direction of memcached
- Requests requests for web page garbled code resolution
- JMeter basic learning records
- XTransfer技术新人进阶秘诀:不可错过的宝藏Mentor
- Shell script
- Subnet partition operation
- Network flow 24 questions (round table questions)
- Unity关于本地坐标和世界坐标之间的转换
- Go coding specification
猜你喜欢
123. the best time to buy and sell shares III
Volcano成Spark默认batch调度器
Capture the whole process of accessing web pages through Wireshark
Return of missing persons
Tdengine can read and write through dataX
关于Unity中的transform.InverseTransformPoint, transform.InverseTransofrmDirection
XTransfer技术新人进阶秘诀:不可错过的宝藏Mentor
Php-pdo parameter binding problem
Static routing job supplement
Page replacement of virtual memory paging mechanism
随机推荐
Memcached full profiling – 1 Fundamentals of memcached
Alibaba cloud schedules tasks and automatically releases them
Reflect package
TDengine可通过数据同步工具 DataX读写
Common data model (updating)
Power apps Guide
Return of missing persons
Second understanding permutation and combination
188. the best time to buy and sell stocks IV
go_ keyword
Markdown use
Blender's simple skills - array, rotation, array and curve
Limit summary (under update)
Big factories go out to sea and lose "posture"
Golang reflection operation collation
memcached全面剖析–2. 理解memcached的内存存储
Arkit与Character Creator动画曲线的对接
B站带货当学新东方
Auto. JS to automatically authorize screen capture permission
JMeter implementation specifies concurrent loop testing