Item0.cs 2.4 KB

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