Item0.cs 3.1 KB

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