RuntimePoint.cs 5.2 KB

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