8 [AddComponentMenu(
"UI/Extensions/UI Highlightable Extension")]
9 [RequireComponent(typeof(RectTransform), typeof(Graphic))]
10 public class UIHighlightable : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IPointerDownHandler, IPointerUpHandler
12 private Graphic m_Graphic;
13 private bool m_Highlighted;
14 private bool m_Pressed;
19 [SerializeField][Tooltip(
"Can this panel be interacted with or is it disabled? (does not affect child components)")]
20 private bool m_Interactable =
true;
21 [SerializeField][Tooltip(
"Does the panel remain in the pressed state when clicked? (default false)")]
22 private bool m_ClickToHold;
26 get {
return m_Interactable; }
29 m_Interactable = value;
30 HighlightInteractable(m_Graphic);
37 get {
return m_ClickToHold; }
38 set { m_ClickToHold = value; }
41 [Tooltip(
"The default color for the panel")]
43 [Tooltip(
"The color for the panel when a mouse is over it or it is in focus")]
45 [Tooltip(
"The color for the panel when it is clicked/held")]
47 [Tooltip(
"The color for the panel when it is not interactable (see Interactable)")]
50 [Tooltip(
"Event for when the panel is enabled / disabled, to enable disabling / enabling of child or other gameobjects")]
55 m_Graphic = GetComponent<Graphic>();
71 m_Highlighted =
false;
83 m_Pressed = !m_Pressed;
90 if(!m_Pressed) HighlightInteractable(m_Graphic);
93 private void HighlightInteractable(Graphic graphic)
113 private void OnValidate()
115 HighlightInteractable(GetComponent<Graphic>());
void OnPointerExit(PointerEventData eventData)
void OnPointerDown(PointerEventData eventData)
void OnPointerEnter(PointerEventData eventData)
InteractableChangedEvent OnInteractableChanged
void OnPointerUp(PointerEventData eventData)
Credit Erdener Gonenc - @PixelEnvision.