|
6 | 6 | using UnityEngine.EventSystems; |
7 | 7 | using UnityEngine.UI; |
8 | 8 |
|
9 | | -#if INCLUDE_TEXT_MESH_PRO |
10 | | -using TMPro; |
11 | | -#endif |
12 | | - |
13 | 9 | [assembly: OptionalDependency("TMPro.TextMeshProUGUI", "INCLUDE_TEXT_MESH_PRO")] |
14 | 10 |
|
15 | 11 | namespace UnityEditor.Experimental.EditorVR.Menus |
16 | 12 | { |
17 | | - sealed class MainMenuButton : MonoBehaviour, ITooltip, IRayEnterHandler, IRayExitHandler, IPointerClickHandler |
| 13 | + sealed class MainMenuButton : MainMenuSelectable, ITooltip, IRayEnterHandler, IRayExitHandler, IPointerClickHandler |
18 | 14 | { |
19 | 15 | [SerializeField] |
20 | 16 | Button m_Button; |
21 | 17 |
|
22 | | -#if INCLUDE_TEXT_MESH_PRO |
23 | | - [SerializeField] |
24 | | - TextMeshProUGUI m_ButtonDescription; |
25 | | -#endif |
26 | | - |
27 | | -#if INCLUDE_TEXT_MESH_PRO |
28 | | - [SerializeField] |
29 | | - TextMeshProUGUI m_ButtonTitle; |
30 | | -#endif |
31 | | - |
32 | | - Color m_OriginalColor; |
| 18 | + CanvasGroup m_CanvasGroup; |
33 | 19 |
|
34 | 20 | public Button button { get { return m_Button; } } |
35 | 21 |
|
36 | 22 | public string tooltipText { get { return tooltip != null ? tooltip.tooltipText : null; } } |
37 | 23 |
|
38 | 24 | public ITooltip tooltip { private get; set; } |
39 | 25 |
|
40 | | - public Type toolType { get; set; } |
41 | | - |
42 | | - public bool selected |
43 | | - { |
44 | | - set |
45 | | - { |
46 | | - if (value) |
47 | | - { |
48 | | - m_Button.transition = Selectable.Transition.None; |
49 | | - m_Button.targetGraphic.color = m_Button.colors.highlightedColor; |
50 | | - } |
51 | | - else |
52 | | - { |
53 | | - m_Button.transition = Selectable.Transition.ColorTint; |
54 | | - m_Button.targetGraphic.color = m_OriginalColor; |
55 | | - } |
56 | | - } |
57 | | - } |
58 | | - |
59 | 26 | public event Action<Transform, Type, string> hovered; |
60 | 27 | public event Action<Transform> clicked; |
61 | 28 |
|
62 | | - void Awake() |
| 29 | + new void Awake() |
63 | 30 | { |
| 31 | + m_Selectable = m_Button; |
64 | 32 | m_OriginalColor = m_Button.targetGraphic.color; |
65 | 33 | } |
66 | 34 |
|
67 | | - public void SetData(string name, string description) |
| 35 | + void Start() |
68 | 36 | { |
69 | | -#if INCLUDE_TEXT_MESH_PRO |
70 | | - m_ButtonTitle.text = name; |
71 | | - m_ButtonDescription.text = description; |
72 | | -#endif |
| 37 | + m_CanvasGroup = m_Button.GetComponentInParent<CanvasGroup>(); |
73 | 38 | } |
74 | 39 |
|
75 | 40 | public void OnRayEnter(RayEventData eventData) |
76 | 41 | { |
| 42 | + if (m_CanvasGroup && !m_CanvasGroup.interactable) |
| 43 | + return; |
| 44 | + |
77 | 45 | #if INCLUDE_TEXT_MESH_PRO |
78 | | - if (hovered != null) |
79 | | - hovered(eventData.rayOrigin, toolType, m_ButtonDescription.text); |
| 46 | + if (button.interactable && hovered != null) |
| 47 | + { |
| 48 | + var descriptionText = string.Empty; |
| 49 | + // We can't use ?? because it breaks on destroyed references |
| 50 | + if (m_Description) |
| 51 | + descriptionText = m_Description.text; |
| 52 | + hovered(eventData.rayOrigin, toolType, descriptionText); |
| 53 | + } |
80 | 54 | #endif |
81 | 55 | } |
82 | 56 |
|
83 | 57 | public void OnRayExit(RayEventData eventData) |
84 | 58 | { |
85 | | - if (hovered != null) |
| 59 | + if (m_CanvasGroup && !m_CanvasGroup.interactable) |
| 60 | + return; |
| 61 | + |
| 62 | + if (button.interactable && hovered != null) |
86 | 63 | hovered(eventData.rayOrigin, null, null); |
87 | 64 | } |
88 | 65 |
|
89 | 66 | public void OnPointerClick(PointerEventData eventData) |
90 | 67 | { |
91 | | - if (clicked != null) |
| 68 | + if (m_CanvasGroup && !m_CanvasGroup.interactable) |
| 69 | + return; |
| 70 | + |
| 71 | + if (button.interactable && clicked != null) |
92 | 72 | clicked(null); // Pass null to perform the selection haptic pulse on both nodes |
93 | 73 | } |
94 | 74 | } |
|
0 commit comments