RuntimePoint.cs 3.8 KB

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