Item0.cs 3.2 KB

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