This commit is contained in:
2026-03-09 09:25:01 +08:00
parent 3dd5a9bf4e
commit e39164fed4
113 changed files with 5154 additions and 3828 deletions
+10 -4
View File
@@ -3,6 +3,7 @@ using Best.WebSockets;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.SceneManagement;
@@ -80,10 +81,10 @@ namespace Assets.MyGame.Scripts.Net
WebSocketSendList.Bind(GameManager.Instance.user.id);
break;
case SocketType.room:
break;
case SocketType.game:
WebSocketSendList.JoinRoom("11109", GameManager.Instance.user.id,1);
break;
case SocketType.chess:
@@ -99,7 +100,11 @@ namespace Assets.MyGame.Scripts.Net
{
Debug.Log($"[WebSocket] {type} 连接关闭 Code:{code} Reason:{reason}");
// 自动重连
StartCoroutine(Reconnect(type));
if (code!=WebSocketStatusCodes.NormalClosure)
{
StartCoroutine(Reconnect(type));
}
};
ws.OnClosed += (web, code, message) =>
@@ -145,7 +150,8 @@ namespace Assets.MyGame.Scripts.Net
{
if (sockets.TryGetValue(type, out var ws))
{
ws.Close();
ws.Close(WebSocketStatusCodes.NormalClosure, "正常关闭"); // 或者 CloseStatusCode.Normal
//ws.Close();
sockets.Remove(type);
}
}