IconTools.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.EventSystems;
  5. using UnityEngine.UI;
  6. public class IconTools : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
  7. {
  8. public GameObject infoImage;
  9. public Image img_bg;
  10. int Index = 0;
  11. [SerializeField] float offsetX = 0;
  12. [SerializeField] float offsety = 0;
  13. bool Isenter = false;
  14. public void OnPointerEnter(PointerEventData eventData)
  15. {
  16. if (infoImage != null)
  17. {
  18. infoImage.SetActive(true);
  19. if (DataManager.Instance.exceptionList.Count > 0)
  20. {
  21. infoImage.GetComponentInChildren<Text>().text = DataManager.Instance.exceptionList[DataManager.Instance.exceptionList.Count - 1 - Index].Time+":"+ DataManager.Instance.exceptionList[DataManager.Instance.exceptionList.Count - 1 - Index].ExceptionMessage;
  22. }
  23. Isenter = true;
  24. }
  25. }
  26. public void OnPointerExit(PointerEventData eventData)
  27. {
  28. if (infoImage != null)
  29. {
  30. infoImage.SetActive(false);
  31. Isenter = false;
  32. }
  33. }
  34. // Start is called before the first frame update
  35. public void SetId(int id)
  36. {
  37. Index = id;
  38. }
  39. // Update is called once per frame
  40. void Update()
  41. {
  42. if (infoImage.activeSelf && Isenter)
  43. {
  44. infoImage.transform.position = Input.mousePosition + new Vector3(offsetX, offsety, 0);
  45. img_bg.transform.position = infoImage.GetComponentInChildren<Text>().transform.position;
  46. img_bg.rectTransform.sizeDelta = new Vector2(infoImage.GetComponentInChildren<Text>().GetComponent<RectTransform>().rect.width, infoImage.GetComponentInChildren<Text>().GetComponent<RectTransform>().rect.height);
  47. }
  48. }
  49. }