2021-03-14 03:56:49 +00:00
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using TMPro;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.EventSystems;
|
|
|
|
|
using UnityEngine.UI;
|
2026-09-14 17:39:12 +02:00
|
|
|
using static CultMath.math;
|
2021-03-14 03:56:49 +00:00
|
|
|
|
|
|
|
|
public class TextButton : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
|
|
|
|
|
{
|
|
|
|
|
public Button Button;
|
|
|
|
|
public TextMeshProUGUI Label;
|
|
|
|
|
public float AnimationDuration;
|
|
|
|
|
public float HoverSpacing;
|
|
|
|
|
|
|
|
|
|
private float _lerp;
|
|
|
|
|
private bool _hovering;
|
|
|
|
|
|
|
|
|
|
// Update is called once per frame
|
|
|
|
|
void Update()
|
|
|
|
|
{
|
|
|
|
|
_lerp = saturate(_lerp + Time.deltaTime / AnimationDuration * (Button.interactable && _hovering ? 1 : -1));
|
|
|
|
|
Label.characterSpacing = HoverSpacing * _lerp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnPointerEnter(PointerEventData eventData)
|
|
|
|
|
{
|
|
|
|
|
_hovering = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnPointerExit(PointerEventData eventData)
|
|
|
|
|
{
|
|
|
|
|
_hovering = false;
|
|
|
|
|
}
|
|
|
|
|
}
|