当前位置:网站首页>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);
}
}
边栏推荐
- XTransfer技术新人进阶秘诀:不可错过的宝藏Mentor
- Requests requests for web page garbled code resolution
- 大厂出海,败于“姿态”
- Network layer
- Axi DMA IP core operation process
- OSI and tcp/ip model
- Auto. JS to automatically authorize screen capture permission
- regular expression
- An example illustrates restful API
- Golang reflection operation collation
猜你喜欢

Page replacement of virtual memory paging mechanism

Network flow 24 questions (round table questions)

Football information query system based on C language course report + project source code + demo ppt+ project screenshot

188. the best time to buy and sell stocks IV

Php-pdo parameter binding problem

The virtual currency evaporated $2trillion in seven months, and the "musks" ended the dream of 150000 people becoming rich

memcached全面剖析–2. 理解memcached的內存存儲

Learn to use a new technology quickly

EditText controls the soft keyboard to search

123. 买卖股票的最佳时机 III
随机推荐
Memcached comprehensive analysis – 5 Memcached applications and compatible programs
Static routing job
Pattern recognition - 0 introduction
[cloud native learning notes] kubernetes practice command
Summary of message protocol problems
Station B takes goods to learn from New Oriental
OSI notes sorting
Realization of truth table assignment by discrete mathematical programming
Analysis of BBR congestion control state machine
【产品设计研发协作工具】上海道宁为您提供蓝湖介绍、下载、试用、教程
CondaValueError: The target prefix is the base prefix. Aborting.
VIM usage
Splicing audio files with ffmpeg-4.3
Blender's simple skills - array, rotation, array and curve
Football information query system based on C language course report + project source code + demo ppt+ project screenshot
[Web Security Basics] some details
Requests requests for web page garbled code resolution
how to install clustershell
Tso hardware sharding is a header copy problem
(to be optimized and modified) vivado DDR4 SDRAM (MIG) (2.2) IP core learning record