当前位置:网站首页>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);
}
}
边栏推荐
猜你喜欢

Microsoft Certification (dynamic 365) test

JMeter basic learning records

Concepts of kubernetes components

JMeter implementation specifies concurrent loop testing

After a few years in the testing industry, do you still know a little?

Arkit与Character Creator动画曲线的对接

Adding subscribers to a list using mailchimp's API V3

Summary of idea practical skills: how to rename a project or module to completely solve all the problems you encounter that do not work. It is suggested that the five-star collection be your daughter

Static routing job supplement

Rewrite, maplocal and maplocal operations of Charles
随机推荐
Go coding specification
Rename and delete files
More than ten years' work experience is recommended at the bottom of the box: how much does it cost to find a job? See here! Brothers and sisters are recommended to collect and pay attention
Nifi fast authentication configuration
Static routing job
Pyaudio audio recording
After screwing the screws in the factory for two years, I earned more than 10000 yuan a month by "testing" and counterattacked
Dijkstra seeking secondary short circuit (easy to understand)
Axi DMA IP core operation process
go_ keyword
Golang daily question
Use of kubernetes storage volumes
Create a multithreaded thread class
Appium desktop introduction
B站带货当学新东方
浅谈MySql update会锁定哪些范围的数据
memcached全面剖析–2. 理解memcached的内存存储
Sleep revolution - find the right length of rest
Football information query system based on C language course report + project source code + demo ppt+ project screenshot
HCIA assessment