From 3159ada61c9907bd641edf4bb66879652ac86332 Mon Sep 17 00:00:00 2001 From: "DESKTOP-SAJ6RKV\\Administrator" Date: Wed, 11 Jun 2025 14:22:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BF=83=E8=B7=B3=E5=8C=85=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../HotFix/GameLogic/ProtCust/ProtCust.cs | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/ProtCust/ProtCust.cs b/UnityProject/Assets/GameScripts/HotFix/GameLogic/ProtCust/ProtCust.cs index 4d65e093..620c7513 100644 --- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/ProtCust/ProtCust.cs +++ b/UnityProject/Assets/GameScripts/HotFix/GameLogic/ProtCust/ProtCust.cs @@ -94,7 +94,7 @@ namespace GameLogic } } - + float timerDt = 2; public void OnUpdate() { if (m_WebSocket != null && m_WebSocket.ReadyState == WebSocketState.Open) @@ -117,8 +117,26 @@ namespace GameLogic item.Value.Clear(); } + timerDt -= Time.deltaTime; + if (timerDt <= 0) + { + // 执行一次Ack + timerDt = 2; + OnHbTimer(); + } + } + /// + /// 心跳包 + /// + private void OnHbTimer() + { + // 心跳包 + Dictionary dis = new Dictionary(); + dis.Add("type", "hb"); + m_WebSocket.SendAsync(dis.ToJson()); + } /// /// 测试服流程初始化