This commit is contained in:
2026-07-10 23:26:42 +08:00
parent fc8ca4e6ba
commit 43065af74f
10 changed files with 1435 additions and 63 deletions
+11 -1
View File
@@ -49,6 +49,14 @@ namespace Assets.MyGame.Scripts.Net
/// 创建或返回已存在的 WebSocket
/// </summary>
public WebSocket Connect(SocketType type,Action action=null)
{
return Connect(type, null, action);
}
/// <summary>
/// 创建或返回已存在的 WebSocket(可指定动态 URL,用于 /api/Room/Assign 返回的房间专属地址)
/// </summary>
public WebSocket Connect(SocketType type, string url, Action action = null)
{
// 已存在则直接返回
if (sockets.TryGetValue(type, out var exist))
@@ -83,7 +91,9 @@ namespace Assets.MyGame.Scripts.Net
}
}
string url = baseUrl + socketPaths[type];
// 未指定 url 时用默认 baseUrl + socketPaths
if (string.IsNullOrEmpty(url))
url = baseUrl + socketPaths[type];
var ws = new WebSocket(new Uri(url));
sockets[type] = ws;
// 事件绑定