RuntimePoint.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. using DG.Tweening;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. using UnityEngine.EventSystems;
  7. using UnityEngine.UI;
  8. public class RuntimePoint : MonoBehaviour, IPointerDownHandler, IPointerUpHandler,IPointerEnterHandler,IPointerExitHandler
  9. {
  10. public string[] childBtnNames = new string[] {
  11. "视频监控",
  12. "雨量监测",
  13. "水文监测",
  14. "水压监测",
  15. "水位监测",
  16. "位移监测",
  17. "泵站",
  18. "闸站"
  19. };
  20. public Action onHoverShowEvent;
  21. public Action onExitHideEvent;
  22. public Action<int, RuntimePoint> onChildClick;
  23. public Button childBtnPrefab;
  24. public Button btn;
  25. public List<Button> listBtns = new List<Button>();
  26. public RectTransform childBtnParent;
  27. public Text text;
  28. public Image icon;
  29. public StaticImportant staticImp;
  30. public List<int> layerIDs = new List<int>();
  31. public RectTransform arrow;
  32. public GameObject bingObj;
  33. public Action onPointClick;
  34. public float lastTime;
  35. public RectTransform addContent;
  36. bool isOver;
  37. float lgtd;
  38. float lttd;
  39. public GameObject lgltObj;
  40. void Awake() {
  41. // arrow.DOLocalMoveY(-40, 1.0f).SetLoops(-1, LoopType.Yoyo);
  42. }
  43. // Start is called before the first frame update
  44. void Start()
  45. {
  46. //this.GetComponent<Button>().onClick.AddListener(() =>
  47. //{
  48. // if (layerIDs.Count > 1)
  49. // {
  50. // addContent.gameObject.SetActive(true);
  51. // if (listBtns.Count < 1)
  52. // {
  53. // for (int i = 0; i < layerIDs.Count; i++)
  54. // {
  55. // Button button = Instantiate(childBtnPrefab);
  56. // button.GetComponent<RectTransform>().SetParent(childBtnParent);
  57. // int temp = i;
  58. // button.GetComponentInChildren<Text>().text = childBtnNames[layerIDs[i]];
  59. // button.transform.localScale = Vector3.one;
  60. // button.gameObject.SetActive(true);
  61. // button.onClick.AddListener(() =>
  62. // {
  63. // onChildClick?.Invoke(layerIDs[temp],this);
  64. // Debug.Log(layerIDs[temp]);
  65. // addContent.gameObject.SetActive(false);
  66. // });
  67. // listBtns.Add(button);
  68. // }
  69. // }
  70. // }
  71. // CameraManager.instance.secondCamera.GetComponent<CameraBirdSec>().beginDrag += () =>
  72. // {
  73. // addContent.gameObject.SetActive(false);
  74. // };
  75. //});
  76. }
  77. public void Refresh(Sprite newIcon) {
  78. icon.sprite = newIcon;
  79. }
  80. public void InitPoint(Sprite newIcon, string name_pri, string newText,float mlgtd,float mlttd) {
  81. text.text = newText;
  82. lgltObj.transform.GetChild(1).GetComponent<Text>().text = "经度:" + mlgtd.ToString("0.000");
  83. lgltObj.transform.GetChild(0).GetComponent<Text>().text = "纬度:" + mlttd.ToString("0.000");
  84. if (name_pri.Trim().Length > 0)
  85. staticImp = StaticLod.instance.staticImportantsDic[name_pri];
  86. icon.sprite = newIcon;
  87. mlgtd = lgtd;
  88. mlttd = lttd;
  89. }
  90. // Update is called once per frame
  91. void LateUpdate()
  92. {
  93. if (CameraManager.instance.secondCamera.enabled)
  94. {
  95. this.GetComponent<RectTransform>().anchoredPosition = CameraManager.instance.secondCamera.WorldToScreenPoint(bingObj.transform.position) * 1920.0f / Screen.width;
  96. float bi = CameraManager.instance.secondCamera.GetComponent<CameraBirdSec>().currentDistance / 20;
  97. bi = (float)Math.Clamp(bi, 0.3, 1);
  98. this.GetComponent<RectTransform>().localScale = Vector3.one / bi;
  99. if (CameraManager.instance.secondCamera.transform.position.z > -625)
  100. {
  101. text.gameObject.SetActive(true);
  102. if (isOver)
  103. {
  104. lgltObj.SetActive(true);
  105. }
  106. else
  107. {
  108. lgltObj.SetActive(false);
  109. }
  110. }
  111. else {
  112. if (isOver)
  113. {
  114. text.gameObject.SetActive(true);
  115. lgltObj.SetActive(true);
  116. }
  117. else
  118. {
  119. text.gameObject.SetActive(false);
  120. lgltObj.SetActive(false);
  121. }
  122. }
  123. }
  124. }
  125. public void OnPointerDown(PointerEventData eventData)
  126. {
  127. if (eventData.button == PointerEventData.InputButton.Left)
  128. {
  129. lastTime = Time.time;
  130. }
  131. }
  132. public void OnPointerUp(PointerEventData eventData)
  133. {
  134. if (eventData.button == PointerEventData.InputButton.Left)
  135. {
  136. if (Time.time - lastTime < 0.5f)
  137. {
  138. isOver = false;
  139. onPointClick?.Invoke();
  140. }
  141. }
  142. }
  143. public void OnPointerEnter(UnityEngine.EventSystems.PointerEventData eventData)
  144. {
  145. isOver = true;
  146. onHoverShowEvent?.Invoke();
  147. }
  148. public void OnPointerExit(UnityEngine.EventSystems.PointerEventData eventData)
  149. {
  150. isOver = false;
  151. onExitHideEvent?.Invoke();
  152. }
  153. }