RuntimePoint.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. void Awake() {
  36. // arrow.DOLocalMoveY(-40, 1.0f).SetLoops(-1, LoopType.Yoyo);
  37. }
  38. // Start is called before the first frame update
  39. void Start()
  40. {
  41. //this.GetComponent<Button>().onClick.AddListener(() =>
  42. //{
  43. // if (layerIDs.Count > 1)
  44. // {
  45. // addContent.gameObject.SetActive(true);
  46. // if (listBtns.Count < 1)
  47. // {
  48. // for (int i = 0; i < layerIDs.Count; i++)
  49. // {
  50. // Button button = Instantiate(childBtnPrefab);
  51. // button.GetComponent<RectTransform>().SetParent(childBtnParent);
  52. // int temp = i;
  53. // button.GetComponentInChildren<Text>().text = childBtnNames[layerIDs[i]];
  54. // button.transform.localScale = Vector3.one;
  55. // button.gameObject.SetActive(true);
  56. // button.onClick.AddListener(() =>
  57. // {
  58. // onChildClick?.Invoke(layerIDs[temp],this);
  59. // Debug.Log(layerIDs[temp]);
  60. // addContent.gameObject.SetActive(false);
  61. // });
  62. // listBtns.Add(button);
  63. // }
  64. // }
  65. // }
  66. // CameraManager.instance.secondCamera.GetComponent<CameraBirdSec>().beginDrag += () =>
  67. // {
  68. // addContent.gameObject.SetActive(false);
  69. // };
  70. //});
  71. }
  72. public void Refresh(Sprite newIcon) {
  73. icon.sprite = newIcon;
  74. }
  75. public void InitPoint(Sprite newIcon, string name_pri, string newText) {
  76. text.text = newText;
  77. if(name_pri.Trim().Length > 0)
  78. staticImp = StaticLod.instance.staticImportantsDic[name_pri];
  79. icon.sprite = newIcon;
  80. }
  81. // Update is called once per frame
  82. void LateUpdate()
  83. {
  84. if (CameraManager.instance.secondCamera.enabled)
  85. {
  86. this.GetComponent<RectTransform>().anchoredPosition = CameraManager.instance.secondCamera.WorldToScreenPoint(bingObj.transform.position) * 1920.0f / Screen.width;
  87. float bi = CameraManager.instance.secondCamera.GetComponent<CameraBirdSec>().currentDistance / 20;
  88. bi = (float)Math.Clamp(bi, 0.3, 1);
  89. this.GetComponent<RectTransform>().localScale = Vector3.one / bi;
  90. if (CameraManager.instance.secondCamera.transform.position.z > -625)
  91. {
  92. text.gameObject.SetActive(true);
  93. }
  94. else {
  95. if(isOver)
  96. text.gameObject.SetActive(true);
  97. else
  98. text.gameObject.SetActive(false);
  99. }
  100. }
  101. }
  102. public void OnPointerDown(PointerEventData eventData)
  103. {
  104. if (eventData.button == PointerEventData.InputButton.Left)
  105. {
  106. lastTime = Time.time;
  107. }
  108. }
  109. public void OnPointerUp(PointerEventData eventData)
  110. {
  111. if (eventData.button == PointerEventData.InputButton.Left)
  112. {
  113. if (Time.time - lastTime < 0.5f)
  114. {
  115. onPointClick?.Invoke();
  116. }
  117. }
  118. }
  119. public void OnPointerEnter(UnityEngine.EventSystems.PointerEventData eventData)
  120. {
  121. isOver = true;
  122. }
  123. public void OnPointerExit(UnityEngine.EventSystems.PointerEventData eventData)
  124. {
  125. isOver = false;
  126. }
  127. }