UGUITooltip.cs 1014 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. namespace XNode.Examples.RuntimeMathNodes {
  6. public class UGUITooltip : MonoBehaviour {
  7. public CanvasGroup group;
  8. public Text label;
  9. private bool show;
  10. private RuntimeMathGraph graph;
  11. private void Awake() {
  12. graph = GetComponentInParent<RuntimeMathGraph>();
  13. }
  14. private void Start() {
  15. Hide();
  16. }
  17. private void Update() {
  18. if (show) UpdatePosition();
  19. }
  20. public void Show() {
  21. show = true;
  22. group.alpha = 1;
  23. UpdatePosition();
  24. transform.SetAsLastSibling();
  25. }
  26. public void Hide() {
  27. show = false;
  28. group.alpha = 0;
  29. }
  30. private void UpdatePosition() {
  31. Vector2 pos;
  32. RectTransform rect = graph.scrollRect.content.transform as RectTransform;
  33. Camera cam = graph.gameObject.GetComponentInParent<Canvas>().worldCamera;
  34. RectTransformUtility.ScreenPointToLocalPointInRectangle(rect, Input.mousePosition, cam, out pos);
  35. transform.localPosition = pos;
  36. }
  37. }
  38. }