TestMapShow.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. using DG.Tweening;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. /// <summary>
  7. /// 显示小地图信息
  8. /// </summary>
  9. public class TestMapShow : MonoBehaviour
  10. {
  11. public RectTransform canvas;
  12. public RectTransform mapPlayer;
  13. public RectTransform mapPlayer2;
  14. public Transform mapParent;
  15. public Image point;
  16. public Color lucency;
  17. public LineRenderer line;
  18. public RectTransform Rpoint;
  19. Vector2 startMapPos;
  20. private void Start()
  21. {
  22. startMapPos = canvas.anchoredPosition;
  23. }
  24. /// <summary>
  25. /// 小地图上所有Image
  26. ///
  27. /// </summary>
  28. public List<Image> listAllPoint;
  29. /// <summary>
  30. /// 显示角色在小地图的位置 ( Position EulerAngles)
  31. /// </summary>
  32. public void ShowPlayer( float x , float y , float rot)
  33. {
  34. Vector2 pos = new Vector2(canvas.rect.width * x > 5 ? canvas.rect.width * x : 5, canvas.rect.height * y > 5 ? canvas.rect.height * y : 5);
  35. mapPlayer.anchoredPosition = pos;
  36. mapPlayer.localRotation = Quaternion.Euler(0, 0, -rot);
  37. }
  38. /// <summary>
  39. /// 显示所有水晶点 (所有可触发交互的地方)
  40. /// </summary>
  41. /// <param name="list_Point"></param>
  42. public void ShowPoint(List<Vector3> list_Point)
  43. {
  44. listAllPoint = new List<Image>();
  45. listAllPoint.Add(mapPlayer.GetComponent<Image>());
  46. listAllPoint.Add(canvas.GetComponent<Image>());
  47. for (int i = 0; i < list_Point.Count; i++)
  48. {
  49. // Debug.Log(list_Point[i]);
  50. Image newPoint = Instantiate(point, canvas);
  51. newPoint.GetComponent<RectTransform>().anchoredPosition =
  52. new Vector2(canvas.rect.width * list_Point[i].x, canvas.rect.height * list_Point[i].y);
  53. // Debug.Log(" Point " + canvas.rect.width * list_Point[i].x+" "+canvas.rect.height * list_Point[i].y);
  54. newPoint.gameObject.SetActive(true);
  55. listAllPoint.Add(newPoint.GetComponent<Image>());
  56. }
  57. mapPlayer.transform.SetAsLastSibling();
  58. LucencyMap();
  59. }
  60. /// <summary>
  61. /// 显示和隐藏地图
  62. /// </summary>
  63. public void ShowMap( bool state)
  64. {
  65. for (int i = 0; i < listAllPoint.Count; i++)
  66. {
  67. listAllPoint[i].DOColor(new Color(listAllPoint[i].color.r, listAllPoint[i].color.g, listAllPoint[i].color.b, state?0: lucency.a), 1f);
  68. }
  69. line.gameObject.SetActive(!state);
  70. }
  71. /// <summary>
  72. /// 设置地图透明度
  73. /// </summary>
  74. public void LucencyMap()
  75. {
  76. for (int i = 0; i < listAllPoint.Count; i++)
  77. {
  78. listAllPoint[i].color = new Color(listAllPoint[i].color.r, listAllPoint[i].color.g, listAllPoint[i].color.b,lucency.a);
  79. }
  80. }
  81. /// <summary>
  82. /// 地图旋转 人不动
  83. /// </summary>
  84. public void MapRot( float x, float y , float rot)
  85. {
  86. Vector2 pos = new Vector2(canvas.rect.width * x > 5 ? canvas.rect.width * x : 5, canvas.rect.height * y > 5 ? canvas.rect.height * y : 5);
  87. mapPlayer2.anchoredPosition = pos;
  88. mapParent.localRotation = Quaternion.Euler(0, 0, rot);
  89. canvas.localRotation = Quaternion.Euler(0, 0, rot);
  90. mapPlayer2.transform.parent = mapPlayer.transform.parent;
  91. canvas.transform.parent = mapPlayer2.transform;
  92. mapPlayer2.anchoredPosition = mapPlayer.anchoredPosition;
  93. canvas.transform.parent = mapPlayer.transform.parent;
  94. mapPlayer2.transform.parent = canvas.transform;
  95. mapPlayer.transform.SetAsLastSibling();
  96. }
  97. public void SettingMapRoute(List<Vector3> listMapRoutePos)
  98. {
  99. line.positionCount = 0;
  100. line.positionCount = listMapRoutePos.Count;
  101. for (int i = 0 ; i < listMapRoutePos.Count; i++)
  102. {
  103. Rpoint.anchoredPosition = new Vector3(canvas.rect.width * listMapRoutePos[i].x, canvas.rect.height * listMapRoutePos[i].y, transform.position.z);
  104. listMapRoutePos[i] = Rpoint.position;
  105. line.SetPosition(i, listMapRoutePos[i]);
  106. }
  107. }
  108. }