| | 1 | | using System; |
| | 2 | | using TMPro; |
| | 3 | | using UnityEngine; |
| | 4 | | using UnityEngine.EventSystems; |
| | 5 | | using UnityEngine.UI; |
| | 6 | |
|
| | 7 | | public class UIPageButton : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler |
| | 8 | | { |
| | 9 | | public event Action<int> OnPageClicked; |
| | 10 | | [SerializeField] private TMP_Text text; |
| | 11 | | [SerializeField] private Button button; |
| | 12 | | [SerializeField] private Animator anim; |
| 0 | 13 | | private static readonly int isActive = Animator.StringToHash("IsActive"); |
| 0 | 14 | | private static readonly int isHover = Animator.StringToHash("IsHover"); |
| | 15 | | private int pageNumber; |
| | 16 | |
|
| 0 | 17 | | private void Awake() { button.onClick.AddListener(OnButtonDown); } |
| 0 | 18 | | private void OnButtonDown() { OnPageClicked?.Invoke(pageNumber); } |
| | 19 | | public void Initialize(int i) |
| | 20 | | { |
| 0 | 21 | | pageNumber = i; |
| 0 | 22 | | text.text = (i + 1).ToString(); |
| 0 | 23 | | } |
| | 24 | |
|
| 0 | 25 | | public void Toggle(bool b) { anim.SetBool(isActive, b); } |
| 0 | 26 | | public void OnPointerEnter(PointerEventData eventData) { anim.SetBool(isHover, true); } |
| 0 | 27 | | public void OnPointerExit(PointerEventData eventData) { anim.SetBool(isHover, false); } |
| | 28 | | } |