Tooltip.cs 1013 B

1234567891011121314151617181920212223242526272829
  1. using UnityEngine;
  2. using UnityEngine.EventSystems;
  3. using UnityEngine.UI;
  4. namespace SoftMasking.Samples {
  5. public class Tooltip : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler {
  6. public RectTransform tooltip;
  7. public void LateUpdate() {
  8. if (tooltip.gameObject.activeInHierarchy) {
  9. Vector2 position;
  10. if (RectTransformUtility.ScreenPointToLocalPointInRectangle(
  11. tooltip.parent.GetComponent<RectTransform>(),
  12. Input.mousePosition,
  13. null,
  14. out position))
  15. tooltip.anchoredPosition = position + new Vector2(10.0f, -20.0f);
  16. }
  17. }
  18. void IPointerEnterHandler.OnPointerEnter(PointerEventData eventData) {
  19. tooltip.gameObject.SetActive(true);
  20. }
  21. void IPointerExitHandler.OnPointerExit(PointerEventData eventData) {
  22. tooltip.gameObject.SetActive(false);
  23. }
  24. }
  25. }