123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class GameManage : MonoSingleton<GameManage>
- {
- /// <summary>
- /// 显示物体
- /// </summary>
- public List<Transform> list_Obj;
- /// <summary>
- /// 物体触发范围 和 list_Obj 按下标对应
- /// </summary>
- public List<Transform> list_Box;
- /// <summary>
- /// 水晶点
- /// </summary>
- public List<Transform> list_Crystal;
- /// <summary>
- /// MeshRoute
- /// </summary>
- public GameObject meshRoute;
- public static string result;
- public static bool state = true;
- public bool isSlam = false;
- /// <summary>
- /// Json
- /// </summary>
- public Root data;
- [HideInInspector]
- public List<GameObject> list_route;
- public TeshMap teshMap;
- bool isInit = true;
- int index = 0;
- private void Start()
- {
- // BlueUdp.logMBSRD += AnalysisJson;
- list_route = new List<GameObject>();
- if (!isSlam)
- HttpSocket.Instance.SendIpToInitialize();
- else
- StartCoroutine(Test());
- }
- /// <summary>
- /// 处理Json 数据
- /// </summary>
- /// <param name="message"></param>
- public void AnalysisJson(string message)
- {
- if (!state)
- return;
- Debug.Log("Message aaa " + message);
- if (message == "" || message == "Message")
- {
- Debug.LogError("未接受到json 数据");
- //udpClient.SendIpToBluetooth();
- HttpSocket.Instance.SendIpToInitialize();
- return;
- }
- data = JsonControl.Instance.ToJsonData(message);
- // Debug.Log(data.navLines.Count);
- if (data == null)
- {
- //udpClient.SendIpToBluetooth();
- HttpSocket.Instance.SendIpToInitialize();
- return;
- }
- if (!isInit)
- return;
- state = false;
- isInit = false;
- // Debug.Log(data.projectId);
- for (int i = 0; i < data.navLines.Count; i++)
- {
- //for (int j = 0; j < data.navLines[i].points.Count; j++)
- //{
- // Debug.Log(data.navLines[i].points[j].MN);
- //}
- SettingLuJing(data.navLines[i], i);
- }
- SettingObj(data);
- //SettingLuJing(data);
- SettingLuJing(0);
- teshMap.SettingMapPoint(list_Crystal);
- teshMap.SettingMapRoute();
- }
- /// <summary>
- /// 设置路径
- /// </summary>
- private void SettingLuJing(Root data)
- {
- for (int i = 0; i < data.navLines.Count; i++)
- {
- for (int j = 0; j < data.navLines[i].points.Count - 1; j++)
- {
- GameObject route = GameObject.Instantiate(meshRoute, meshRoute.transform.parent);
- Vector3 endPos = new Vector3((float)data.navLines[i].points[j].X, 0, (float)data.navLines[i].points[j].Y);
- Vector3 exitPos = new Vector3((float)data.navLines[i].points[j + 1].X, 0, (float)data.navLines[i].points[j + 1].Y);
- Debug.Log(endPos + " " + exitPos);
- route.GetComponent<TestRoute>().SetRoute(endPos, exitPos);
- route.SetActive(true);
- }
- }
- }
- private void SettingLuJing(NavLinesItem data, int Index)
- {
- GameObject routes = new GameObject("Route" + Index.ToString());
- routes.transform.parent = meshRoute.transform.parent;
- for (int j = 0; j < data.points.Count - 1; j++)
- {
- GameObject route = GameObject.Instantiate(meshRoute, routes.transform);
- Vector3 endPos = new Vector3((float)data.points[j].X, 0, (float)data.points[j].Y);
- Vector3 exitPos = new Vector3((float)data.points[j + 1].X, 0, (float)data.points[j + 1].Y);
- // Debug.Log(endPos + " " + exitPos);
- route.GetComponent<TestRoute>().SetRoute(endPos, exitPos, Index);
- route.SetActive(true);
- // 地图显示路径
- teshMap.ADDMapRoutePoint(endPos, Index);
- }
- teshMap.ADDMapRoutePoint(new Vector3((float)data.points[data.points.Count - 1].X, 0, (float)data.points[data.points.Count - 1].Y), Index);
- // teshMap.SettingMapRoute();
- list_route.Add(routes);
- }
- public void SettingLuJing(int Index)
- {
- if (list_route == null || list_route.Count < Index)
- {
- Debug.LogError(" 未初始化路径 或 所选的路径不存在 ");
- return;
- }
- for (int i = 0; i < list_route.Count; i++)
- {
- list_route[i].SetActive(false);
- }
- list_route[Index].SetActive(true);
- }
- private void Update()
- {
- //if (state && UdpClient.logMBSRD != null)
- //{
- // Debug.Log(" UdpClient.logMBSRD");
- // UdpClient.logMBSRD(result);
- // // UdpClient.logMBSRD -= AnalysisJson;
- // //state = false;
- //}
- //times += Time.deltaTime;
- //if(times>0.5f && API_SVR.GetHead()!=null)
- //{
- // times = 0;
- // Vector3 pos = new Vector3(API_SVR.GetHead().position.x, API_SVR.GetHead().position.z, 0);
- // string Ts = ((DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000000).ToString();
- // udpClient.SendIpToPointCloud(pos, Ts);
- //}
- }
- /// <summary>
- /// 设置物体位置 和 触发范围
- /// </summary>
- /// <param name="data"></param>
- private void SettingObj(Root data)
- {
- for (int i = 0; i < data.navLines.Count; i++)
- {
- for (int j = 0; j < data.navLines[i].points.Count; j++)
- {
- if (data.navLines[i].points[j].T == 1)
- {
- switch (data.navLines[i].points[j].MN)
- {
- case "Party":
- QueryBox("Party", data.navLines[i].points[j]);
- break;
- case "Gongye":
- QueryBox("Gongye", data.navLines[i].points[j]);
- break;
- case "Subway":
- QueryBox("Subway", data.navLines[i].points[j]);
- break;
- case "Chemical":
- QueryBox("Chemical", data.navLines[i].points[j]);
- break;
- case "Library":
- //// 博物馆 前4个触发器改为一个触发器
- //int index = 0;
- //SettingBox(list_Box[list_Box.Count - 1], new Vector3((float)data.navLines[i].points[j].X, (float)data.navLines[i].points[j].Z, (float)data.navLines[i].points[j].Y));
- QueryBox("Museum", data.navLines[i].points[j]);
- //foreach (MPItem item in data.navLines[i].points[j].MP)
- //{
- // SettingBox(list_Obj[index++], item);
- //}
- break;
- case "YiLiao":
- QueryBox("YiLiao", data.navLines[i].points[j]);
- break;
- default:
- break;
- }
- }
- }
- }
- }
- /// <summary>
- /// 查询
- /// </summary>
- /// <param name="Name"></param>
- /// <param name="points"></param>
- private void QueryBox(string Name, PointsItem points)
- {
- for (int i = 0; i < list_Obj.Count; i++)
- {
- if (list_Obj[i].name == Name)
- {
- SettingBox(list_Box[i], list_Obj[i], list_Crystal[i], points);
- Debug.Log("AAAAAAAA+ " + list_Box[i].name + list_Crystal[i].name + list_Obj[i].name);
- break;
- }
- }
- }
- /// <summary>
- /// 设置物体位置 和触发范围
- /// </summary>
- /// <param name="box">触发器</param>
- /// <param name="obj">显示物体</param>
- /// <param name="crystal">水晶点</param>
- /// <param name="points"></param>
- private void SettingBox(Transform box, Transform obj, Transform crystal, PointsItem points)
- {
- box.position = new Vector3((float)points.X, -1f, (float)points.Y);
- crystal.position = new Vector3(box.position.x, -3f, box.position.z);
- obj.position = new Vector3((float)points.MP[0].X, points.MP[0].Z == -1 ? obj.position.y : (float)points.MP[0].Z, (float)points.MP[0].Y);
- Debug.Log(obj.name + " " + obj.position);
- }
- private void SettingBox(Transform obj, MPItem mpItem)
- {
- obj.position = new Vector3((float)mpItem.X, mpItem.Z == -1 ? obj.position.y : (float)mpItem.Z, (float)mpItem.Y);
- }
- private void SettingBox(Transform obj, Vector3 mpItem)
- {
- //Debug.Log(obj.name);
- obj.position = new Vector3((float)mpItem.x, obj.position.y, (float)mpItem.y);
- list_Crystal[0].position = new Vector3(obj.position.x, -2.5f, obj.position.z);
- }
- IEnumerator Test()
- {
- WWW www = new WWW(Application.streamingAssetsPath + "/projectInfo.json");
- yield return www;
- string message = www.text;
- Debug.Log(message);
- AnalysisJson(message);
- }
- }
|