HintText.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.EventSystems;
  5. /// <summary>
  6. /// Attach this script to a ui element, when mouse hover it, a small floating panel with hint text will show up
  7. /// </summary>
  8. namespace SoftKitty
  9. {
  10. public class HintText : MonoBehaviour,IPointerEnterHandler,IPointerExitHandler
  11. {
  12. #region Variables
  13. public string HintString = "";
  14. private bool isHover = false;
  15. #endregion
  16. #region Internal Methods
  17. public void OnPointerEnter(PointerEventData eventData)
  18. {
  19. isHover = true;
  20. }
  21. public void OnPointerExit(PointerEventData eventData)
  22. {
  23. isHover = false;
  24. }
  25. private void OnDisable()
  26. {
  27. isHover = false;
  28. }
  29. public bool GetHover()
  30. {
  31. return isHover;
  32. }
  33. void Update()
  34. {
  35. if (isHover)
  36. {
  37. if (HintString != "") HintManager.ShowHint(HintString,this);
  38. }
  39. }
  40. #endregion
  41. }
  42. }