using System; using System.Collections; using System.Collections.Generic; using UnityEngine; /* * 1. 场景中ABCD四个Cube 对应场景内的四个角 * 2. SceneRoot 位置默认要与A点的位置相同 * 3. 场景内尺寸比例根据图片比例进行动态的修改 * 4. 所有的计算和同步都是在开头的沙盘播放结束后进行 * */ /// /// 计算人物在地图上的位置 /// public class CalMap : MonoBehaviour { /// /// 场景中的Player /// public Transform player; [SerializeField] private MinMap m_Map; private void LateUpdate() { if (OpenXRCamera.Instance.head != null) { if (player != null && GameManager.Instance.isStart) { float rot = player.localEulerAngles.y; var pos = new Vector3(Math.Abs(player.localPosition.x) / GameManager.Instance.MapSize.x * GameManager.Instance.MinMapSize.x, -(GameManager.Instance.MinMapSize.y- (Math.Abs(player.localPosition.z) / GameManager.Instance.MapSize.y * GameManager.Instance.MinMapSize.y)), 0); if (pos.x < 0) { pos.x = 0; } if (pos.x > GameManager.Instance.MinMapSize.x) { pos.x = GameManager.Instance.MinMapSize.x; } if (pos.y > 0) { pos.y = 0; } if (pos.y < -GameManager.Instance.MinMapSize.y) { pos.y = -GameManager.Instance.MinMapSize.y; } m_Map.ShowPlayer(pos, rot); } } } public void SettingMapPoint(List list_Pos) { MapPoint(list_Pos); } /// /// 设置小地图路线 /// /// public void SetLines(NavLinesItem data) { if (data == null) return; List pos = new List(); for (int j = 0; j < data.lines.Count; j++) { var line = data.lines[j]; 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); 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); pos.Add(startPos); if (j == data.lines.Count - 1) { pos.Add(endPos); } } m_Map.SettingMapRoute(pos, data.name); } /// /// 计算场景水晶点位置 /// private void MapPoint(List listPoint) { if (listPoint.Count <= 0) return; List Points = new List(); for (int i = 0; i < listPoint.Count; i++) { var pos = listPoint[i].localPosition; float x = Mathf.Abs(pos.x) / GameManager.Instance.MapSize.x * GameManager.Instance.MinMapSize.x; float y = Mathf.Abs(pos.z) / GameManager.Instance.MapSize.y * GameManager.Instance.MinMapSize.y; Points.Add(new Vector3(x, y, 0)); } m_Map.ShowPoint(Points); } }