当前位置:网站首页>Slider控制Animator动画播放进度
Slider控制Animator动画播放进度
2022-06-24 19:19:00 【南宫铭】
前言
在某些应用场景中可能需要用Slider控制动画的播放进度,什么点击啊,拖拽啊,搜索一番发现都是使用的是Animation,毕竟直接有API可以调用相当的方便,可Animation是旧版的东西了,今天来说说怎么控制Animator动画,代码还是很简单的
代码
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)
{
//获取当前动画片段信息
animatorStateInfo = Animator.GetCurrentAnimatorStateInfo(0);
//normalizedTime 是个0-1的值 代表进度
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);
//从指定进度开始播放
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);
}
}
边栏推荐
- how to install clustershell
- Page replacement of virtual memory paging mechanism
- Learn together and make progress together. Welcome to exchange
- TCP_ Nodelay and TCP_ CORK
- An example illustrates restful API
- Rewrite, maplocal and maplocal operations of Charles
- GDB debugging
- Big factories go out to sea and lose "posture"
- Call process of package receiving function
- 188. 买卖股票的最佳时机 IV
猜你喜欢
去掉录屏提醒(七牛云demo)
Power apps Guide
It was Tencent who jumped out of the job with 26k. It really wiped my ass with sandpaper. It gave me a hand
Dynamic routing protocol rip, OSPF
Record a deletion bash_ Profile file
[email protected] -Perfmon metric collector listener steps"/>
JMeter installation plug-in, adding [email protected] -Perfmon metric collector listener steps
The virtual currency evaporated $2trillion in seven months, and the "musks" ended the dream of 150000 people becoming rich
JMeter basic learning records
Common data model (updating)
188. 买卖股票的最佳时机 IV
随机推荐
DHCP operation
What will you do if you have been ignored by your leaders at work?
Rip/ospf protocol notes sorting
Tso hardware sharding is a header copy problem
基于C语言实现的足球信息查询系统 课程报告+项目源码+演示PPT+项目截图
yeb_ Back first day
Station B takes goods to learn from New Oriental
Network security review office starts network security review on HowNet
Variable setting in postman
Nifi quick installation (stand-alone / cluster)
Auto. JS to automatically authorize screen capture permission
Basic database syntax learning
Rewrite, maplocal and maplocal operations of Charles
Failed to open after installing Charles without any prompt
Self signed certificate generation
After a few years in the testing industry, do you still know a little?
Concepts of kubernetes components
Please open online PDF carefully
Common self realization functions in C language development
After idea installs these plug-ins, the code can be written to heaven. My little sister also has to arrange it