基础内容
必要插件安装 缓动曲线和动画基础 ElementFolder,Track与其次级模块,PathNode重构
This commit is contained in:
55
Assets/Modern UI Pack/Scripts/Icon/AnimatedIconHandler.cs
Normal file
55
Assets/Modern UI Pack/Scripts/Icon/AnimatedIconHandler.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace Michsky.MUIP
|
||||
{
|
||||
[RequireComponent(typeof(Animator))]
|
||||
public class AnimatedIconHandler : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IPointerClickHandler
|
||||
{
|
||||
[Header("Settings")]
|
||||
public PlayType playType;
|
||||
public Animator iconAnimator;
|
||||
|
||||
bool isClicked;
|
||||
|
||||
public enum PlayType
|
||||
{
|
||||
Click,
|
||||
Hover,
|
||||
None
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (iconAnimator == null)
|
||||
iconAnimator = gameObject.GetComponent<Animator>();
|
||||
}
|
||||
|
||||
public void PlayIn() { iconAnimator.Play("In"); }
|
||||
public void PlayOut() { iconAnimator.Play("Out"); }
|
||||
|
||||
public void ClickEvent()
|
||||
{
|
||||
if (isClicked == true) { PlayOut(); isClicked = false; }
|
||||
else { PlayIn(); isClicked = true; }
|
||||
}
|
||||
|
||||
public void OnPointerClick(PointerEventData eventData)
|
||||
{
|
||||
if (playType == PlayType.Click)
|
||||
ClickEvent();
|
||||
}
|
||||
|
||||
public void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
if (playType == PlayType.Hover)
|
||||
iconAnimator.Play("In");
|
||||
}
|
||||
|
||||
public void OnPointerExit(PointerEventData eventData)
|
||||
{
|
||||
if (playType == PlayType.Hover)
|
||||
iconAnimator.Play("Out");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user