当前位置:网站首页>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);
}
}
边栏推荐
- Limit summary (under update)
- Pytest testing framework
- [cloud native learning notes] kubernetes Foundation
- Network flow 24 questions (round table questions)
- 基于STM32的物联网下智能化养鱼鱼缸控制控制系统
- GDB debugging
- CondaValueError: The target prefix is the base prefix. Aborting.
- AntDB数据库在线培训开课啦!更灵活、更专业、更丰富
- Kernel Debugging Tricks
- Codeforces Round #720 (Div. 2)
猜你喜欢

Address mapping of virtual memory paging mechanism

Analyse complète Memcached – 2. Comprendre le stockage de mémoire pour Memcached

Page replacement of virtual memory paging mechanism

Concepts of kubernetes components

Capture the whole process of accessing web pages through Wireshark

XTransfer技术新人进阶秘诀:不可错过的宝藏Mentor

BPF_ PROG_ TYPE_ SOCKET_ Filter function implementation

Web project deployment

Multi view function in blender

Volcano成Spark默认batch调度器
随机推荐
Axi DMA IP core operation process
Minimum cost and maximum flow (template question)
memcached全面剖析–3. memcached的删除机制和发展方向
关于Unity中的transform.InverseTransformPoint, transform.InverseTransofrmDirection
[cloud native learning notes] learn about kubernetes configuration list yaml file
Power apps Guide
Requests requests for web page garbled code resolution
装修首页自定义全屏视频播放效果gif动态图片制作视频教程播放代码操作设置全屏居中阿里巴巴国际站
Analysis of BBR congestion control state machine
Appium introduction and environment installation
RFC 793 why to send reset and when to send reset
Learn to use a new technology quickly
Appium desktop introduction
Functional analysis of ebpf tracepoint
Web project deployment
Use of kubernetes storage volumes
Volcano成Spark默认batch调度器
Oauth1.0 introduction
Please open online PDF carefully
BBR bandwidth per second conversion logic