Item0.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. // Start is called before the first frame update
  19. void Start()
  20. {
  21. }
  22. public void InitPoint(Sprite newIcon, string name_pri, string newText, string special)
  23. {
  24. if (special != "1")
  25. {
  26. bg.gameObject.SetActive(false);
  27. this.GetComponentInChildren<Button>().targetGraphic = nameText;
  28. this.GetComponent<RectTransform>().sizeDelta = new Vector2(this.GetComponent<RectTransform>().sizeDelta.x, 70);
  29. }
  30. else
  31. {
  32. switch (name_pri)
  33. {
  34. case "BuYuan":
  35. pic.GetComponent<Image>().sprite = images[0];
  36. break;
  37. case "TaoKou":
  38. pic.GetComponent<Image>().sprite = images[1];
  39. break;
  40. case "YaoKou":
  41. pic.GetComponent<Image>().sprite = images[2];
  42. break;
  43. case "GeTi":
  44. pic.GetComponent<Image>().sprite = images[3];
  45. break;
  46. }
  47. }
  48. nameText.text = newText;
  49. if (name_pri.Trim().Length > 0)
  50. {
  51. staticImp = StaticLod.instance.staticImportantsDic[name_pri];
  52. bingObj = staticImp.gameObject;
  53. }
  54. icon.sprite = newIcon;
  55. }
  56. void LateUpdate()
  57. {
  58. if (CameraManager.instance.mainCamera.GetComponent<CameraBird>().onScroll)
  59. {
  60. pic.GetComponent<Image>().raycastTarget = false;
  61. nameText.raycastTarget = false;
  62. }
  63. else
  64. {
  65. pic.GetComponent<Image>().raycastTarget = true;
  66. nameText.raycastTarget = true;
  67. }
  68. this.GetComponent<RectTransform>().anchoredPosition = CameraManager.instance.mainCamera.WorldToScreenPoint(bingObj.transform.position) * 1920.0f / Screen.width;
  69. float bi = CameraManager.instance.mainCamera.GetComponent<CameraBird>().currentDistance / 20;
  70. bi = (float)Math.Clamp(bi, 0.3, 1);
  71. this.GetComponent<RectTransform>().localScale = Vector3.one / bi;
  72. }
  73. public void OnPointerDown(PointerEventData eventData)
  74. {
  75. pic.GetComponent<Image>().color = Color.gray;
  76. if (eventData.button == PointerEventData.InputButton.Left)
  77. {
  78. lastTime = Time.time;
  79. }
  80. }
  81. public void OnPointerUp(PointerEventData eventData)
  82. {
  83. pic.GetComponent<Image>().color = Color.white;
  84. if (eventData.button == PointerEventData.InputButton.Left)
  85. {
  86. if (Time.time - lastTime < 0.5f)
  87. {
  88. onPointClick?.Invoke();
  89. }
  90. }
  91. }
  92. }