1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- 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 (API_GSXR_Slam.GSXR_Get_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, -Math.Abs(player.localPosition.z) / GameManager.Instance.MapSize.y * GameManager.Instance.MinMapSize.y, 0);
-
- if (player.localPosition.x < 0 || player.localPosition.z > 0)
- {
- return;
- }
- // Debug.Log(pos);
- 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);
- }
- }
|