Item0.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using System;
  6. using UnityEngine.EventSystems;
  7. public class Item0 : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
  8. {
  9. public float lastTime;
  10. public Action onPointClick;
  11. public Image icon;
  12. public GameObject bg;
  13. public Image pic;
  14. public Text nameText;
  15. public StaticImportant staticImp;
  16. public GameObject bingObj;
  17. public Sprite[] images;
  18. public string mSpecial;
  19. // Start is called before the first frame update
  20. void Start()
  21. {
  22. }
  23. public void InitPoint(Sprite newIcon, string name_pri, string newText, string special)
  24. {
  25. mSpecial = special;
  26. if (special != "1")
  27. {
  28. bg.gameObject.SetActive(false);
  29. this.GetComponentInChildren<Button>().targetGraphic = nameText;
  30. this.GetComponent<RectTransform>().sizeDelta = new Vector2(this.GetComponent<RectTransform>().sizeDelta.x, 70);
  31. }
  32. else
  33. {
  34. switch (name_pri)
  35. {
  36. case "BuYuan":
  37. pic.GetComponent<Image>().sprite = images[0];
  38. break;
  39. case "TaoKou":
  40. pic.GetComponent<Image>().sprite = images[1];
  41. break;
  42. case "YaoKou":
  43. pic.GetComponent<Image>().sprite = images[2];
  44. break;
  45. case "ZhuGeDi":
  46. pic.GetComponent<Image>().sprite = images[3];
  47. break;
  48. case "YaoKouGeDi":
  49. pic.GetComponent<Image>().sprite = images[4];
  50. break;
  51. case "ChangJiangGanDi":
  52. pic.GetComponent<Image>().sprite = images[5];
  53. break;
  54. case "DongJingHe":
  55. pic.GetComponent<Image>().sprite = images[6];
  56. break;
  57. }
  58. }
  59. nameText.text = newText;
  60. if (name_pri.Trim().Length > 0)
  61. {
  62. staticImp = StaticLod.instance.staticImportantsDic[name_pri];
  63. bingObj = staticImp.gameObject;
  64. }
  65. icon.sprite = newIcon;
  66. }
  67. void LateUpdate()
  68. {
  69. if (CameraManager.instance.mainCamera.GetComponent<CameraBird>().onScroll)
  70. {
  71. pic.GetComponent<Image>().raycastTarget = false;
  72. nameText.raycastTarget = false;
  73. }
  74. else
  75. {
  76. pic.GetComponent<Image>().raycastTarget = true;
  77. nameText.raycastTarget = true;
  78. }
  79. this.GetComponent<RectTransform>().anchoredPosition = CameraManager.instance.mainCamera.WorldToScreenPoint(bingObj.transform.position) * 1920.0f / Screen.width;
  80. float bi = CameraManager.instance.mainCamera.GetComponent<CameraBird>().currentDistance / 20;
  81. bi = (float)Math.Clamp(bi, 0.3, 1);
  82. this.GetComponent<RectTransform>().localScale = Vector3.one / bi;
  83. }
  84. public void OnPointerDown(PointerEventData eventData)
  85. {
  86. pic.GetComponent<Image>().color = Color.gray;
  87. if (eventData.button == PointerEventData.InputButton.Left)
  88. {
  89. lastTime = Time.time;
  90. }
  91. }
  92. public void OnPointerUp(PointerEventData eventData)
  93. {
  94. pic.GetComponent<Image>().color = Color.white;
  95. if (eventData.button == PointerEventData.InputButton.Left)
  96. {
  97. if (Time.time - lastTime < 0.5f)
  98. {
  99. onPointClick?.Invoke();
  100. }
  101. }
  102. }
  103. }