12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- /*
- * 1. 场景中ABCD四个Cube 对应场景内的四个角
- * 2. SceneRoot 位置默认要与A点的位置相同
- * 3. 场景内尺寸比例根据图片比例进行动态的修改
- * 4. 所有的计算和同步都是在开头的沙盘播放结束后进行
- *
- */
- /// <summary>
- /// 计算人物在地图上的位置
- /// </summary>
- public class CalMap : MonoBehaviour
- {
- /// <summary>
- /// 场景中的Player
- /// </summary>
- 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-180;
- 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);
-
- if (player.localPosition.x < 0 || player.localPosition.y > 0)
- {
- return;
- }
- m_Map.ShowPlayer(pos, rot);
- }
- }
- }
- public void SettingMapPoint(List<Transform> list_Pos)
- {
- MapPoint(list_Pos);
- }
- /// <summary>
- /// 设置小地图路线
- /// </summary>
- /// <param name="data"></param>
- public void SetLines(NavLinesItem data)
- {
- if (data == null)
- return;
- List<Vector3> pos = new List<Vector3>();
- 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);
- }
-
- /// <summary>
- /// 计算场景水晶点位置
- /// </summary>
- private void MapPoint(List<Transform> listPoint)
- {
- if (listPoint.Count <= 0)
- return;
- List<Vector3> Points = new List<Vector3>();
- 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);
- }
- }
|