Browse Source

解决开启时偶尔路线获取失败的问题

wangxin 4 years ago
parent
commit
19a893f042
1 changed files with 33 additions and 32 deletions
  1. 33 32
      Assets/XDKUnityCloudExamples/Common/Scripts/Test/TestJsonManage.cs

+ 33 - 32
Assets/XDKUnityCloudExamples/Common/Scripts/Test/TestJsonManage.cs

@@ -47,24 +47,25 @@ public class TestJsonManage : MonoBehaviour
     /// 处理Json 数据
     /// </summary>
     /// <param name="message"></param>
-    private void AnalysisJson( string message )
+    private void AnalysisJson(string message)
     {
         if (!state)
-            return; 
+            return;
         Debug.Log("Message  aaa  " + message);
-        if(message == ""||message == "Message")
+        if (message == "" || message == "Message")
         {
             Debug.LogError("未接受到json 数据");
+            udpClient.SendIpToBluetooth();
             return;
         }
 
-        if(!isInit)    
+        if (!isInit)
             return;
-        
+
         isInit = false;
 
-         data = JsonControl.Instance().ToJsonData(message);
-    //    Debug.Log(data.navLines.Count);
+        data = JsonControl.Instance().ToJsonData(message);
+        //    Debug.Log(data.navLines.Count);
         if (data == null)
             return;
         //  Debug.Log(data.projectId);
@@ -84,11 +85,11 @@ public class TestJsonManage : MonoBehaviour
     /// <summary>
     ///  设置路径
     /// </summary>
-    private void SettingLuJing( Root data)
+    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++)
+            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);
@@ -102,24 +103,24 @@ public class TestJsonManage : MonoBehaviour
 
     }
 
-    private void SettingLuJing(NavLinesItem data , int Index)
+    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);
-            }
+        {
+            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);
+        }
         list_route.Add(routes);
     }
     public void SettingLuJing(int Index)
     {
-        if(list_route ==null||list_route.Count<Index)
+        if (list_route == null || list_route.Count < Index)
         {
             Debug.LogError(" 未初始化路径 或 所选的路径不存在 ");
             return;
@@ -135,7 +136,7 @@ public class TestJsonManage : MonoBehaviour
 
     private void Update()
     {
-        if(state && UdpClient.logMBSRD!=null)
+        if (state && UdpClient.logMBSRD != null)
         {
             Debug.Log("              UdpClient.logMBSRD");
             UdpClient.logMBSRD(result);
@@ -160,7 +161,7 @@ public class TestJsonManage : MonoBehaviour
     ///  设置物体位置 和 触发范围 
     /// </summary>
     /// <param name="data"></param>
-    private void SettingObj( Root data)
+    private void SettingObj(Root data)
     {
         for (int i = 0; i < data.navLines.Count; i++)
         {
@@ -171,7 +172,7 @@ public class TestJsonManage : MonoBehaviour
                     switch (data.navLines[i].points[j].MN)
                     {
                         case "Transformers":
-                            QueryBox("P6", data.navLines[i].points[j]);  
+                            QueryBox("P6", data.navLines[i].points[j]);
                             break;
                         case "Car":
                             QueryBox("P4Car", data.navLines[i].points[j]);
@@ -186,7 +187,7 @@ public class TestJsonManage : MonoBehaviour
                             foreach (MPItem item in data.navLines[i].points[j].MP)
                             {
                                 SettingBox(list_Obj[index++], item);
-                            }                         
+                            }
                             break;
                         default:
                             break;
@@ -202,7 +203,7 @@ public class TestJsonManage : MonoBehaviour
     /// <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)
@@ -213,7 +214,7 @@ public class TestJsonManage : MonoBehaviour
             }
         }
     }
-   
+
     /// <summary>
     /// 设置物体位置 和触发范围
     /// </summary>
@@ -221,22 +222,22 @@ public class TestJsonManage : MonoBehaviour
     /// <param name="obj">显示物体</param>
     /// <param name="crystal">水晶点</param>
     /// <param name="points"></param>
-    private void SettingBox( Transform box , Transform obj, Transform crystal,  PointsItem points )
+    private void SettingBox(Transform box, Transform obj, Transform crystal, PointsItem points)
     {
-        box.position = new Vector3((float)points.X, -1f, (float)points.Y);     
+        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);     
+        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);
     }
- 
+
     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);
+        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);
+        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);
     }
 
@@ -244,7 +245,7 @@ public class TestJsonManage : MonoBehaviour
     {
         WWW www = new WWW(Application.streamingAssetsPath + "/projectInfo.json");
         yield return www;
-        string  message = www.text;
+        string message = www.text;
         Debug.Log(message);
         AnalysisJson(message);
     }