RuntimePoint.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using DG.Tweening;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. using UnityEngine.EventSystems;
  7. using UnityEngine.UI;
  8. public class RuntimePoint : MonoBehaviour,IPointerDownHandler,IPointerUpHandler
  9. {
  10. public Button btn;
  11. public Text text;
  12. public Image icon;
  13. public StaticImportant staticImp;
  14. public List<int> layerIDs = new List<int>();
  15. public RectTransform arrow;
  16. public GameObject bingObj;
  17. public Action onPointClick;
  18. public float lastTime;
  19. void Awake() {
  20. // arrow.DOLocalMoveY(-40, 1.0f).SetLoops(-1, LoopType.Yoyo);
  21. }
  22. // Start is called before the first frame update
  23. void Start()
  24. {
  25. }
  26. public void Refresh(Sprite newIcon) {
  27. Debug.Log(newIcon);
  28. Debug.Log(bingObj.name);
  29. icon.sprite = newIcon;
  30. }
  31. public void InitPoint(Sprite newIcon, string name_pri, string newText) {
  32. text.text = newText;
  33. if(name_pri.Trim().Length > 0)
  34. staticImp = StaticLod.instance.staticImportantsDic[name_pri];
  35. icon.sprite = newIcon;
  36. }
  37. // Update is called once per frame
  38. void LateUpdate()
  39. {
  40. this.GetComponent<RectTransform>().anchoredPosition = CameraManager.instance.secondCamera.WorldToScreenPoint(bingObj.transform.position) * 1920.0f / Screen.width;
  41. float bi = CameraManager.instance.secondCamera.GetComponent<CameraBirdSec>().currentDistance / 20;
  42. bi = (float)Math.Clamp(bi, 0.3, 1);
  43. this.GetComponent<RectTransform>().localScale = Vector3.one / bi;
  44. }
  45. public void OnPointerDown(PointerEventData eventData)
  46. {
  47. lastTime = Time.time;
  48. }
  49. public void OnPointerUp(PointerEventData eventData)
  50. {
  51. if (Time.time - lastTime < 0.5f)
  52. {
  53. onPointClick?.Invoke();
  54. }
  55. }
  56. }