Item0.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. }
  55. }
  56. nameText.text = newText;
  57. if (name_pri.Trim().Length > 0)
  58. {
  59. staticImp = StaticLod.instance.staticImportantsDic[name_pri];
  60. bingObj = staticImp.gameObject;
  61. }
  62. icon.sprite = newIcon;
  63. }
  64. void LateUpdate()
  65. {
  66. if (CameraManager.instance.mainCamera.GetComponent<CameraBird>().onScroll)
  67. {
  68. pic.GetComponent<Image>().raycastTarget = false;
  69. nameText.raycastTarget = false;
  70. }
  71. else
  72. {
  73. pic.GetComponent<Image>().raycastTarget = true;
  74. nameText.raycastTarget = true;
  75. }
  76. this.GetComponent<RectTransform>().anchoredPosition = CameraManager.instance.mainCamera.WorldToScreenPoint(bingObj.transform.position) * 1920.0f / Screen.width;
  77. float bi = CameraManager.instance.mainCamera.GetComponent<CameraBird>().currentDistance / 20;
  78. bi = (float)Math.Clamp(bi, 0.3, 1);
  79. this.GetComponent<RectTransform>().localScale = Vector3.one / bi;
  80. }
  81. public void OnPointerDown(PointerEventData eventData)
  82. {
  83. pic.GetComponent<Image>().color = Color.gray;
  84. if (eventData.button == PointerEventData.InputButton.Left)
  85. {
  86. lastTime = Time.time;
  87. }
  88. }
  89. public void OnPointerUp(PointerEventData eventData)
  90. {
  91. pic.GetComponent<Image>().color = Color.white;
  92. if (eventData.button == PointerEventData.InputButton.Left)
  93. {
  94. if (Time.time - lastTime < 0.5f)
  95. {
  96. onPointClick?.Invoke();
  97. }
  98. }
  99. }
  100. }