HKI Core
UITooltip.cs
Go to the documentation of this file.
1 using UnityEngine;
2 using UnityEngine.EventSystems;
3 using HKI.Core.Loc;
4 
5 namespace HKI.Core.UI
6 {
10  public class UITooltip : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
11  {
12  // Public enums
13  [System.Serializable]
14  public enum TooltipAlingments
15  {
16  BottomRight,
17  TopLeft,
18  BottomLeft,
19  TopRight
20  }
21 
22  // Public variables
23  [SerializeField] TooltipAlingments TooltipAlingment = TooltipAlingments.BottomRight;
24  [SerializeField] TextLocalization TooltipTextLocalization = null;
25 
26  // Getter
27  public TooltipAlingments GetTooltipAlingment { get { return TooltipAlingment; } }
28 
29  // OnDisable function
30  void OnDisable()
31  {
32  if(UITooltipController.Instance == null)
33  {
34  //Debug.LogError("(UITooltipController)" + name + " you are trying to hide a tooltip but there is no tooltip controller in this scene(s)!");
35  return;
36  }
37 
39  }
40 
41  // Interface implementations
43  {
44  if (tl != null)
45  TooltipTextLocalization = tl;
46  }
47 
48  public void OnPointerEnter(PointerEventData eventData)
49  {
50  if(TooltipTextLocalization == null)
51  {
52  Debug.LogError("(UITooltip)" + name + " you are trying use a text localization but there is no text localization attached to this tooltip!");
53  return;
54  }
55 
56  if(UITooltipController.Instance == null)
57  {
58  Debug.LogError("(UITooltipController)" + name + " you are trying to show a tooltip but there is no tooltip controller in this scene(s)!");
59  return;
60  }
61 
62  UITooltipController.Instance.ShowTooltip(this, TooltipTextLocalization);
63  }
64 
65  public void OnPointerExit(PointerEventData eventData)
66  {
67  if (UITooltipController.Instance == null)
68  {
69  Debug.LogError("(UITooltipController)" + name + " you are trying to hide a tooltip but there is no tooltip controller in this scene(s)!");
70  return;
71  }
72 
74  }
75  }
76 }
This ScriptableObject contains as a container for all text localization information.
void ShowTooltip(UITooltip tooltip, TextLocalization textLocalization)
This MonoBehaviour is responseble for the displaying of a tooltip. It needs a window GameObject and a...
void ChangeTooltipTextLocalization(TextLocalization tl)
Definition: UITooltip.cs:42
static UITooltipController Instance
void HideTooltip(UITooltip tooltip)
Attached to a GameObject with a RectTransform this MonoBehaviour will display a tooltip if the mouse ...
Definition: UITooltip.cs:10
void OnPointerEnter(PointerEventData eventData)
Definition: UITooltip.cs:48
void OnPointerExit(PointerEventData eventData)
Definition: UITooltip.cs:65