From b6ca4d3f1efb73979f781545628f89c79169bb14 Mon Sep 17 00:00:00 2001 From: Kevin Li Date: Wed, 30 Aug 2023 16:49:30 +0800 Subject: [PATCH] Add close connection --- Assets/Scenes/Test.unity | 2 +- Assets/Scripts/GameClient.cs | 4 +++- Assets/Scripts/KcpDofClient.cs | 5 +++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Assets/Scenes/Test.unity b/Assets/Scenes/Test.unity index c9eb981..2666ca7 100644 --- a/Assets/Scenes/Test.unity +++ b/Assets/Scenes/Test.unity @@ -772,7 +772,7 @@ RectTransform: m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMax: {x: 0.5, y: 0.5} m_AnchoredPosition: {x: 0, y: 0} - m_SizeDelta: {x: 1000, y: 100} + m_SizeDelta: {x: 1000, y: 200} m_Pivot: {x: 0.5, y: 0.5} --- !u!1 &549377895 GameObject: diff --git a/Assets/Scripts/GameClient.cs b/Assets/Scripts/GameClient.cs index 324a7c6..737e671 100644 --- a/Assets/Scripts/GameClient.cs +++ b/Assets/Scripts/GameClient.cs @@ -49,6 +49,8 @@ public class GameClient : MonoBehaviour { _kcpDofClient.OnConnected -= OnConnected; _kcpDofClient.OnServerMessage -= OnServerMessage; + + _kcpDofClient.Close(); } IEnumerator _DelayCall(float delay_secs, Action callback) @@ -187,7 +189,7 @@ public class GameClient : MonoBehaviour { if (msg.PlayerEntered != null) { - infoText.text = $"Player Enter cid: {msg.PlayerEntered.Cid}, Waiting for player"; + infoText.text = $"{nickName} Enter cid: {msg.PlayerEntered.Cid}, Waiting for other player"; goes[1].SetActive(false); } else if (msg.GameStart != null) diff --git a/Assets/Scripts/KcpDofClient.cs b/Assets/Scripts/KcpDofClient.cs index 246a61e..3f0196b 100644 --- a/Assets/Scripts/KcpDofClient.cs +++ b/Assets/Scripts/KcpDofClient.cs @@ -63,6 +63,11 @@ public class KcpDofClient : KcpListener dataBuf.Release(); } + public void Close() + { + _kcpClient.stop(); + } + public void onConnected(Ukcp ukcp) { Debug.Log($"[KcpDofClient]onConnected");