当前位置:网站首页>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);
}
}
边栏推荐
- Limit summary (under update)
- Tool composition in JMeter
- 浅谈MySql update会锁定哪些范围的数据
- Curl command
- Realization of truth table assignment by discrete mathematical programming
- Analysis of tcpdump packet capturing kernel code
- 2021-09-30
- Pyaudio audio recording
- After 5 months' test, it took 15K to come for an interview. When I asked, it was not worth even 5K. It was really
- Php-pdo parameter binding problem
猜你喜欢

VirtualBox虚拟机安装Win10企业版

What are the problems with traditional IO? Why is zero copy introduced?

JMeter implementation specifies concurrent loop testing

I feel that I am bald again when I help my children with their homework. I feel pity for my parents all over the world

Web automation: summary of special scenario processing methods

Microsoft Certification (dynamic 365) test

Read all text from stdin to a string

OSI notes sorting

ping: www.baidu.com: 未知的名称或服务

Dynamic routing protocol rip, OSPF
随机推荐
After idea installs these plug-ins, the code can be written to heaven. My little sister also has to arrange it
TCP Jprobe utilization problem location
Subnet partition operation
memcached完全剖析–1. memcached的基础
PIXIV Gizmo
EditText 控制软键盘出现 搜索
123. 买卖股票的最佳时机 III
Pytest test framework II
Several common command operations in win system
大厂出海,败于“姿态”
Requests requests for web page garbled code resolution
Shell script
JMeter basic learning records
Learn together and make progress together. Welcome to exchange
Packaging_ Conversion between basic type and string type
[cloud native learning notes] kubernetes practice command
VirtualBox虚拟机安装Win10企业版
Poj1061 frog dating (extended Euclid)
OSI and tcp/ip model
yeb_ Back first day