123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class MapView_ : MonoBehaviour
- {
- public GameManage manage;
- public TeshMap teshMap;
- public Transform player;
- public Transform map_player;
- public Transform mapPointA;
- public Transform mapPointB;
- public List<Transform> list_Point;
- public GameObject meshRoute;
- public List<Transform> list_route;
- public float disX = 0;
- public float disZ = 0;
- private void OnEnable()
- {
-
- if (API_SVR.GetHead()==null)
- {
- Debug.LogError("场景未初始化完成");
- return;
- }
- SettingPoint();
- SettingRoute();
- SettingPlayer();
- }
- /// <summary>
- /// 场景内水晶点在场景的比例 算出 在3DMap上应该出现的位置
- /// 博物馆4个合一个 从第三个开始
- /// </summary>
- public void SettingPoint()
- {
- for (int i = 0; i < list_Point.Count; i++)
- {
- // Vector3 pos = GetDisPos(manage.list_Crystal[i + 3].localPosition);
- Debug.Log(manage.list_Crystal[i + 3].localPosition + " " + teshMap.disX + " " + teshMap.disZ);
- Vector3 pos = manage.list_Crystal[i + 3].localPosition;
- pos = new Vector3(pos.z, 0, pos.x);
- pos = GetDisPos(pos);
- pos = new Vector3(pos.x, pos.y, -pos.z);
- list_Point[i].localPosition = pos + new Vector3(0, -0.3f, 0);
- }
- }
- public void SettingRoute()
- {
- #region old
- //for (int i = 0; i < manage.data.navLines.Count; i++)
- //{
- // GameObject routes = new GameObject("Route" + i.ToString());
- // routes.transform.parent = meshRoute.transform.parent;
- // for (int j = 0; j < manage.data.navLines[i].points.Count-1; j++)
- // {
- // GameObject route = GameObject.Instantiate(meshRoute, routes.transform);
- // Vector3 endPos = new Vector3((float)manage.data.navLines[i].points[j].X, 0, (float)manage.data.navLines[i].points[j].Y);
- // Vector3 exitPos = new Vector3((float)manage.data.navLines[i].points[j + 1].X, 0, (float)manage.data.navLines[i].points[j + 1].Y);
- // Debug.Log(endPos + " " + exitPos);
- // endPos = GetDisPos(endPos);
- // exitPos = GetDisPos(exitPos);
- // Debug.Log(endPos + " " + exitPos);
- // route.transform.localPosition = (endPos + exitPos) / 2.0f;
- // // route.GetComponent<TestRoute>().SetMapRoute(endPos, exitPos);
- // route.SetActive(true);
- // }
- //}
- #endregion
- if (list_route == null)
- list_route = new List<Transform>();
- for (int i = 0; i < manage.list_route.Count; i++)
- {
- GameObject routes = new GameObject("Route" + i.ToString());
- routes.transform.parent = meshRoute.transform.parent;
- routes.transform.localPosition = Vector3.zero;
- list_route.Add(routes.transform);
- for (int j = 0; j < manage.list_route[i].transform.childCount; j++)
- {
- Vector3 pos = GetDisPos(manage.list_route[i].transform.GetChild(j).localPosition);
- //Vector3 pos = manage.list_route[i].transform.GetChild(j).localPosition;
- //pos = new Vector3(pos.z, 0, pos.x);
- //pos = GetDisPos(pos);
- // Debug.Log(manage.list_route[i].transform.GetChild(j).localPosition +" "+ teshMap.disX +" "+ teshMap.disZ);
- GameObject route = GameObject.Instantiate(meshRoute, routes.transform);
- route.transform.localPosition = pos + new Vector3(0, 0f, 0);
- route.transform.localRotation = manage.list_route[i].transform.GetChild(j).localRotation;
- // Debug.Log(route.transform.localPosition);
- Vector3 endPos = manage.list_route[i].transform.GetChild(j).GetComponent<TestRoute>().endPos;
- Vector3 exitPos = manage.list_route[i].transform.GetChild(j).GetComponent<TestRoute>().exitPos;
- //endPos = GetDisPos(endPos);
- //exitPos = GetDisPos(exitPos);
- // route.GetComponent<TestRoute>().SetMapRoute();
- route.GetComponent<TestRoute>().SetMapRoute(endPos , exitPos);
- route.transform.localScale += manage.list_route[i].transform.GetChild(j).localScale / 15.0f;
- route.SetActive(true);
- }
- }
- SwitchRoute(0);
- }
- public void SwitchRoute( int Index)
- {
- if (list_route == null || list_route.Count < Index)
- {
- Debug.LogError(" 未初始化路径 或 所选的路径不存在 ");
- return;
- }
- if (list_route.Count >Index)
- {
- for (int i = 0; i < list_route.Count; i++)
- {
- list_route[i].gameObject.SetActive(false);
- }
- list_route[Index].gameObject.SetActive(true);
- }
- }
- public void SettingPlayer()
- {
- Vector3 pos = GetDisPos(player.position);
- Debug.Log(player.position + " " + pos);
- map_player.localPosition = pos;
- }
- /// <summary>
- /// 按照当前场景比例 算出物体在场景内应该出现的位置
- /// localPosition
- /// </summary>
- private Vector3 GetDisPos( Vector3 pos)
- {
- if (disX == 0)
- {
- disX = Mathf.Abs(mapPointB.localPosition.x - mapPointA.localPosition.x);
- disZ = Mathf.Abs(mapPointB.localPosition.z - mapPointA.localPosition.z);
- }
- float x =pos.x / teshMap.disZ;
- float z = pos.z / teshMap.disX;
- //Debug.Log(x +" "+ z);
- Vector3 disPos = new Vector3(x * disX, 0, z * disZ);
- return disPos;
- }
- }
|