Browse Source

新增断线重连

DGJ 1 year ago
parent
commit
073a92085e

+ 7 - 2
Assets/Prefab/Route/Materials/LineMat_1.mat

@@ -2,14 +2,17 @@
 %TAG !u! tag:unity3d.com,2011:
 --- !u!21 &2100000
 Material:
-  serializedVersion: 6
+  serializedVersion: 8
   m_ObjectHideFlags: 0
   m_CorrespondingSourceObject: {fileID: 0}
   m_PrefabInstance: {fileID: 0}
   m_PrefabAsset: {fileID: 0}
   m_Name: LineMat_1
   m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
-  m_ShaderKeywords: _ALPHABLEND_ON _EMISSION
+  m_ValidKeywords:
+  - _ALPHABLEND_ON
+  - _EMISSION
+  m_InvalidKeywords: []
   m_LightmapFlags: 1
   m_EnableInstancingVariants: 0
   m_DoubleSidedGI: 0
@@ -56,6 +59,7 @@ Material:
         m_Texture: {fileID: 0}
         m_Scale: {x: 1, y: 1}
         m_Offset: {x: 0, y: 0}
+    m_Ints: []
     m_Floats:
     - _BumpScale: 1
     - _Cutoff: 0.5
@@ -76,3 +80,4 @@ Material:
     m_Colors:
     - _Color: {r: 1, g: 1, b: 1, a: 1}
     - _EmissionColor: {r: 1, g: 1, b: 1, a: 1}
+  m_BuildTextureStacks: []

+ 120 - 0
Assets/Resources/RouteItem.prefab

@@ -0,0 +1,120 @@
+%YAML 1.1
+%TAG !u! tag:unity3d.com,2011:
+--- !u!1 &3745312271860900176
+GameObject:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  serializedVersion: 6
+  m_Component:
+  - component: {fileID: 3745312271860900177}
+  - component: {fileID: 3745312271860900181}
+  - component: {fileID: 3745312271860900180}
+  - component: {fileID: 3745312271860900179}
+  - component: {fileID: 3745312271860900178}
+  m_Layer: 0
+  m_Name: RouteItem
+  m_TagString: Untagged
+  m_Icon: {fileID: 0}
+  m_NavMeshLayer: 0
+  m_StaticEditorFlags: 0
+  m_IsActive: 0
+--- !u!4 &3745312271860900177
+Transform:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 3745312271860900176}
+  m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
+  m_LocalPosition: {x: 0, y: 0, z: 0}
+  m_LocalScale: {x: 0.05, y: 1, z: 0.05}
+  m_ConstrainProportionsScale: 0
+  m_Children: []
+  m_Father: {fileID: 0}
+  m_RootOrder: 0
+  m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
+--- !u!33 &3745312271860900181
+MeshFilter:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 3745312271860900176}
+  m_Mesh: {fileID: 10209, guid: 0000000000000000e000000000000000, type: 0}
+--- !u!23 &3745312271860900180
+MeshRenderer:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 3745312271860900176}
+  m_Enabled: 1
+  m_CastShadows: 1
+  m_ReceiveShadows: 1
+  m_DynamicOccludee: 1
+  m_StaticShadowCaster: 0
+  m_MotionVectors: 1
+  m_LightProbeUsage: 1
+  m_ReflectionProbeUsage: 1
+  m_RayTracingMode: 2
+  m_RayTraceProcedural: 0
+  m_RenderingLayerMask: 1
+  m_RendererPriority: 0
+  m_Materials:
+  - {fileID: 2100000, guid: 0f8ae0187a5a6c04eb7606fe00b5e5d2, type: 2}
+  m_StaticBatchInfo:
+    firstSubMesh: 0
+    subMeshCount: 0
+  m_StaticBatchRoot: {fileID: 0}
+  m_ProbeAnchor: {fileID: 0}
+  m_LightProbeVolumeOverride: {fileID: 0}
+  m_ScaleInLightmap: 1
+  m_ReceiveGI: 1
+  m_PreserveUVs: 0
+  m_IgnoreNormalsForChartDetection: 0
+  m_ImportantGI: 0
+  m_StitchLightmapSeams: 1
+  m_SelectedEditorRenderState: 3
+  m_MinimumChartSize: 4
+  m_AutoUVMaxDistance: 0.5
+  m_AutoUVMaxAngle: 89
+  m_LightmapParameters: {fileID: 0}
+  m_SortingLayerID: 0
+  m_SortingLayer: 0
+  m_SortingOrder: 0
+  m_AdditionalVertexStreams: {fileID: 0}
+--- !u!64 &3745312271860900179
+MeshCollider:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 3745312271860900176}
+  m_Material: {fileID: 0}
+  m_IsTrigger: 0
+  m_Enabled: 1
+  serializedVersion: 4
+  m_Convex: 0
+  m_CookingOptions: 30
+  m_Mesh: {fileID: 10209, guid: 0000000000000000e000000000000000, type: 0}
+--- !u!114 &3745312271860900178
+MonoBehaviour:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 3745312271860900176}
+  m_Enabled: 1
+  m_EditorHideFlags: 0
+  m_Script: {fileID: 11500000, guid: 7bd7613742397b0478fe9b5e1c8f8e01, type: 3}
+  m_Name: 
+  m_EditorClassIdentifier: 
+  ListLineMat:
+  - {fileID: 2100000, guid: 0f8ae0187a5a6c04eb7606fe00b5e5d2, type: 2}
+  - {fileID: 2100000, guid: 3a5a2e1c7de626148bc11b260327baca, type: 2}
+  - {fileID: 2100000, guid: c48bcd49845c6eb4fb04b33c70ff5e41, type: 2}
+  Point: {fileID: 0}
+  EndPos: {x: 0, y: 0, z: 0}
+  StartPos: {x: 0, y: 0, z: 0}

+ 7 - 0
Assets/Resources/RouteItem.prefab.meta

@@ -0,0 +1,7 @@
+fileFormatVersion: 2
+guid: 5c04824020f93a64b99e33f31b4884a5
+PrefabImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 36 - 12
Assets/Script/MQTTClient.cs

@@ -37,6 +37,8 @@ public class MQTTClient : MonoSingleton<MQTTClient>
     private void OnReceived(MqttMsgPublishEventArgs obj)
     {
         rlist.Enqueue(obj);
+
+
     }
 
     private void OnConnecting()
@@ -138,6 +140,7 @@ public class MQTTClient : MonoSingleton<MQTTClient>
         DisConnect();
         qt = new QTTManager(id, username, password);
         qt.Connect();
+        StartCoroutine(Reconnection());
         qt.ConnectionFailed += onFaild;
         qt.ConnectionSucceeded += onSucceed;
         qt.OnConnecting += OnConnecting;
@@ -148,8 +151,25 @@ public class MQTTClient : MonoSingleton<MQTTClient>
     private void OnClose(EventArgs obj)
     {
         Debug.Log("断开连接");
+
+        
+    }
+
+    private IEnumerator Reconnection()
+    {
+        while (true)
+        {
+            yield return new WaitForSeconds(5);
+            if(qt!=null&&!qt.IsConnect())
+            {
+                Debug.Log(" DGJ ===>  Reconnection ");
+                Connect();
+            }         
+        }
     }
 
+
+
     //断开连接
     public void DisConnect()
     {
@@ -187,18 +207,22 @@ public class MQTTClient : MonoSingleton<MQTTClient>
     IEnumerator sendCameraPos()
     {
         Debug.Log("DGJ  =====>  sendCameraPos" + qt.IsConnect());
-        while (qt.IsConnect())
+        while (true)
         {
-            JsonData json = new JsonData();
-            json["type"] = "CamPos";
-            //  json["x"] = OpenXRCamera.Instance.head.position.x;
-            //json["y"] = OpenXRCamera.Instance.head.position.y;
-            //json["z"] = OpenXRCamera.Instance.head.position.z;
-            json["x"] = GameManager.Instance.Player.transform.localPosition.x;    
-            json["y"] = GameManager.Instance.Player.transform.localPosition.y;
-            json["z"] = GameManager.Instance.Player.transform.localPosition.z;
-            json["Sid"] = "sid";//选择的场景id
-            publish(Encoding.UTF8.GetBytes(json.ToJson()));
+            if(qt!=null&& qt.IsConnect())
+            {
+                JsonData json = new JsonData();
+                json["type"] = "CamPos";
+                //  json["x"] = OpenXRCamera.Instance.head.position.x;
+                //json["y"] = OpenXRCamera.Instance.head.position.y;
+                //json["z"] = OpenXRCamera.Instance.head.position.z;
+                json["x"] = GameManager.Instance.Player.transform.localPosition.x;
+                json["y"] = GameManager.Instance.Player.transform.localPosition.y;
+                json["z"] = GameManager.Instance.Player.transform.localPosition.z;
+                json["Sid"] = "sid";//选择的场景id
+                publish(Encoding.UTF8.GetBytes(json.ToJson()));
+            }
+           
             yield return new WaitForSeconds(0.1f);
         }
     }
@@ -232,7 +256,7 @@ public class MQTTClient : MonoSingleton<MQTTClient>
 
     void publish(byte[] bs)
     {
-        if(qt.IsConnect())
+        if(qt!=null&& qt.IsConnect())
         {
             Debug.Log(id + "  DGJ  publish =====>  " + rid + "   " + bs.Length);
             qt.Publish(rid, bs, MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, false);

+ 2 - 0
Assets/Scripts/Blue/Service/IMQTTService.cs

@@ -222,6 +222,7 @@ public class MQTTService : IMQTTService
     private void OnDisconnected()
     {
         Debug.LogError("断开连接`");
+      
     }
 
     /// <summary>
@@ -230,6 +231,7 @@ public class MQTTService : IMQTTService
     private void OnConnectionLost()
     {
         Debug.LogError("连接丢失");
+
     }
 
     /// <summary>

+ 3 - 6
ProjectSettings/ProjectSettings.asset

@@ -147,10 +147,7 @@ PlayerSettings:
     16:9: 1
     Others: 1
   bundleVersion: 10.13.3
-  preloadedAssets:
-  - {fileID: -6682207197718421661, guid: 8f422df2931cba0478c1fe8ab232b9a3, type: 2}
-  - {fileID: 3493090336618791480, guid: 2d049ae1db0e2b74c8251022ae6dcb95, type: 2}
-  - {fileID: 4800000, guid: c9f956787b1d945e7b36e0516201fc76, type: 3}
+  preloadedAssets: []
   metroInputSource: 0
   wsaTransparentSwapchain: 0
   m_HolographicPauseOnTrackingLoss: 1
@@ -927,6 +924,7 @@ PlayerSettings:
   metroSplashScreenUseBackgroundColor: 1
   platformCapabilities:
     WindowsStoreApps:
+      EnterpriseAuthentication: False
       OfflineMapsManagement: False
       HumanInterfaceDevice: False
       Location: False
@@ -939,7 +937,6 @@ PlayerSettings:
       InternetClientServer: False
       VideosLibrary: False
       Objects3D: False
-      InternetClient: True
       RemoteSystem: False
       BlockedChatMessages: False
       PhoneCall: False
@@ -961,9 +958,9 @@ PlayerSettings:
       RecordedCallsFolder: False
       Contacts: False
       Proximity: False
+      InternetClient: True
       CodeGeneration: False
       BackgroundMediaPlayback: False
-      EnterpriseAuthentication: False
   metroTargetDeviceFamilies:
     Desktop: False
     Holographic: False