CalMap.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. /*
  6. * 1. 场景中ABCD四个Cube 对应场景内的四个角
  7. * 2. SceneRoot 位置默认要与A点的位置相同
  8. * 3. 场景内尺寸比例根据图片比例进行动态的修改
  9. * 4. 所有的计算和同步都是在开头的沙盘播放结束后进行
  10. *
  11. */
  12. /// <summary>
  13. /// 计算人物在地图上的位置
  14. /// </summary>
  15. public class CalMap : MonoBehaviour
  16. {
  17. /// <summary>
  18. /// 场景中的Player
  19. /// </summary>
  20. public Transform player;
  21. [SerializeField]
  22. private MinMap m_Map;
  23. private void LateUpdate()
  24. {
  25. if (OpenXRCamera.Instance.head != null)
  26. {
  27. if (player != null && GameManager.Instance.isStart)
  28. {
  29. float rot = player.localEulerAngles.y-180;
  30. var pos = new Vector3(GameManager.Instance.MinMapSize.x-Math.Abs(player.localPosition.x) / GameManager.Instance.MapSize.x * GameManager.Instance.MinMapSize.x, -Math.Abs(player.localPosition.z) / GameManager.Instance.MapSize.y * GameManager.Instance.MinMapSize.y, 0);
  31. if (player.localPosition.x < 0 || player.localPosition.y > 0)
  32. {
  33. return;
  34. }
  35. m_Map.ShowPlayer(pos, rot);
  36. }
  37. }
  38. }
  39. public void SettingMapPoint(List<Transform> list_Pos)
  40. {
  41. MapPoint(list_Pos);
  42. }
  43. /// <summary>
  44. /// 设置小地图路线
  45. /// </summary>
  46. /// <param name="data"></param>
  47. public void SetLines(NavLinesItem data)
  48. {
  49. if (data == null)
  50. return;
  51. List<Vector3> pos = new List<Vector3>();
  52. for (int j = 0; j < data.lines.Count; j++)
  53. {
  54. var line = data.lines[j];
  55. Vector3 startPos = new Vector3((float)line.x1 / GameManager.Instance.WebMapSize.x * GameManager.Instance.MinMapSize.x, -(float)line.y1 / GameManager.Instance.WebMapSize.y * GameManager.Instance.MinMapSize.y, 0);
  56. Vector3 endPos = new Vector3((float)line.x2 / GameManager.Instance.WebMapSize.x * GameManager.Instance.MinMapSize.x, -(float)line.y2 / GameManager.Instance.WebMapSize.y * GameManager.Instance.MinMapSize.y, 0);
  57. pos.Add(startPos);
  58. if (j == data.lines.Count - 1)
  59. {
  60. pos.Add(endPos);
  61. }
  62. }
  63. m_Map.SettingMapRoute(pos, data.name);
  64. }
  65. /// <summary>
  66. /// 计算场景水晶点位置
  67. /// </summary>
  68. private void MapPoint(List<Transform> listPoint)
  69. {
  70. if (listPoint.Count <= 0)
  71. return;
  72. List<Vector3> Points = new List<Vector3>();
  73. for (int i = 0; i < listPoint.Count; i++)
  74. {
  75. var pos = listPoint[i].localPosition;
  76. float x = Mathf.Abs(pos.x) / GameManager.Instance.MapSize.x * GameManager.Instance.MinMapSize.x;
  77. float y = Mathf.Abs(pos.z) / GameManager.Instance.MapSize.y * GameManager.Instance.MinMapSize.y;
  78. Points.Add(new Vector3(x, y, 0));
  79. }
  80. m_Map.ShowPoint(Points);
  81. }
  82. }