123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class TestJsonManage : MonoBehaviour
- {
-
-
-
- public List<Transform> list_Obj;
-
-
-
- public List<Transform> list_Box;
-
-
-
- public List<Transform> list_Crystal;
-
-
-
- public GameObject meshRoute;
- public UdpClient udpClient;
- public static string result;
- public static bool state = true;
- public bool isSlam = false;
-
-
-
- public Root data;
- [HideInInspector]
- public List<GameObject> list_route;
- public TeshMap teshMap;
- bool isInit = true;
- int index = 0;
- private void Start()
- {
-
- list_route = new List<GameObject>();
- if (!isSlam)
- UdpClient.logMBSRD += AnalysisJson;
- else
- StartCoroutine(Test());
- }
-
-
-
-
- public void AnalysisJson( string message )
- {
- if (!state)
- return;
- Debug.Log("Message aaa " + message);
- if(message == ""||message == "Message")
- {
- Debug.LogError("未接受到json 数据");
- udpClient.SendIpToBluetooth();
- return;
- }
-
- data = JsonControl.Instance.ToJsonData(message);
-
- if (data == null)
- {
- udpClient.SendIpToBluetooth();
- return;
- }
- if (!isInit)
- return;
- state = false;
- isInit = false;
-
- for (int i = 0; i < data.navLines.Count; i++)
- {
-
-
-
-
- SettingLuJing(data.navLines[i], i);
- }
- SettingObj(data);
-
- SettingLuJing(0);
- teshMap.SettingMapPoint(list_Crystal);
- teshMap.SettingMapRoute();
- }
-
-
-
- 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);
-
- 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);
-
- 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);
-
-
- }
-
-
-
-
-
-
-
-
- }
-
-
-
-
- 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":
-
-
-
- QueryBox("Library", data.navLines[i].points[j]);
-
-
-
-
- break;
- default:
- break;
- }
- }
- }
- }
- }
-
-
-
-
-
- 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;
- }
- }
- }
-
-
-
-
-
-
-
-
- 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)
- {
-
- 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);
- }
- }
|