| | 1 | | using System; |
| | 2 | | using TMPro; |
| | 3 | | using UnityEngine; |
| | 4 | | using UnityEngine.UI; |
| | 5 | |
|
| | 6 | | namespace UIComponents.Scripts.Components |
| | 7 | | { |
| | 8 | | public class PageSelectorButtonComponentView : BaseComponentView |
| | 9 | | { |
| | 10 | | public event Action<int> OnPageClicked; |
| | 11 | |
|
| | 12 | | [SerializeField] private TMP_Text text; |
| | 13 | | [SerializeField] private Button button; |
| | 14 | | [SerializeField] private Animator anim; |
| | 15 | |
|
| 1 | 16 | | private static readonly int IS_ACTIVE = Animator.StringToHash("IsActive"); |
| 1 | 17 | | private static readonly int IS_HOVER = Animator.StringToHash("IsHover"); |
| | 18 | |
|
| | 19 | | private int pageNumber; |
| | 20 | |
|
| | 21 | | public override void Awake() |
| | 22 | | { |
| 35 | 23 | | base.Awake(); |
| 35 | 24 | | button.onClick.AddListener(OnButtonDown); |
| 35 | 25 | | } |
| | 26 | |
|
| 0 | 27 | | public override void RefreshControl() { } |
| | 28 | |
|
| | 29 | | public void Initialize(int i) |
| | 30 | | { |
| 35 | 31 | | pageNumber = i; |
| 35 | 32 | | text.text = (i + 1).ToString(); |
| 35 | 33 | | } |
| | 34 | |
|
| | 35 | | public void Toggle(bool b) => |
| 70 | 36 | | anim.SetBool(IS_ACTIVE, b); |
| | 37 | |
|
| | 38 | | private void OnButtonDown() => |
| 0 | 39 | | OnPageClicked?.Invoke(pageNumber); |
| | 40 | |
|
| | 41 | | public override void OnFocus() => |
| 0 | 42 | | anim.SetBool(IS_HOVER, true); |
| | 43 | |
|
| | 44 | | public override void OnLoseFocus() => |
| 40 | 45 | | anim.SetBool(IS_HOVER, false); |
| | 46 | | } |
| | 47 | | } |