123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- 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;
- 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<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);
- }
- }
|