From 523dc168c9fe7c0fb8d8329fa4e80d6d0c62878c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A3=AE2003?= <2384017988@qq.com> Date: Thu, 30 Jul 2026 01:06:55 +0800 Subject: [PATCH] 1 --- .../Windows/addressables_content_state.bin | Bin 4130 -> 4130 bytes Assets/MyGame/Scripts/Net/APIManager.cs | 4 +- Assets/MyGame/Scripts/Net/WebSocketManager.cs | 4 +- .../Scripts/Net/WebSocketReponseList.cs | 11 +-- .../aa/UI/Game/GameMainPanel_FishBase.cs | 85 +++++++++++++++--- 5 files changed, 80 insertions(+), 24 deletions(-) diff --git a/Assets/AddressableAssetsData/Windows/addressables_content_state.bin b/Assets/AddressableAssetsData/Windows/addressables_content_state.bin index 994e12693960b906f9902f5d3095b93db7cbf513..d11d36f60d61f9e2a64511ab2fe228f6719fe256 100644 GIT binary patch delta 634 zcmZ3aut;G;6|;g#YNAYNGMxSy<7$g~{nI|VDnHZWH7#dopCRvyn8kt!dTN)W!8kk!ePhQNLH@TSAVzMWj z&}4bmkja8<7L#AF2{CqojabEIH@S@+B;!BXlU-CH(a0nv#Ue2+(ahY?*wWn4G||F5 z$pYj`bK?|K1LMsq9Q&D62zgI>?upLH?A*Of6|W~x<6fmg$fG--)SZ}|!sFl@-u{mh z=sgBTAd&*oB0$V$03-6zLX75<^LbVIPatVh z6HuG1$R|Ge08qs(pbD$WZ+TS(jv}eJ9>UHzc>$l8F`=+d-=OIUvLE3k+sWB{sse|Q P44a>m!Ma(FpM?$Z~8Y zEwxsLqpVbh7P)3tSgLjJ<@BwPD?y}|Ii@&MrbNULE+}Oh5k{C6StzdIS7KV z=B`;6(F#0{?!!t{K(AuqBr56`eLo)cTW}Wb)K`5i8PzVinY-|-dj1-sOk|cCDKJ)r z%5hedNLj|E;5Z{}v@`Yd_0jxg_t=Hk)!Wdmv{Ed%l*nLHFqB(Pkzq<%TVh3cnM=}Z z&wiY0Px7F3bmtLNYui)JKJ3@twkNr9^Jn}3^!$zH!QR=N`%e(MbHU|B7ZHLYW?=@; zlbpQQeph;_z{wB45?zIU(rJ7iTlf9VlM1{_ns}0>TaDBH|6t private static void ExitFishingGame(UIPanel gamePanel) { @@ -546,15 +545,11 @@ namespace Assets.MyGame.Scripts.Net GameManager.Instance.UpdataUserData(user); }); - // ⭐ 复用游戏面板的 JinDuTiao 进度条卸载资源,完成后进入 home 界面 + // ⭐ 通知面板 socket 已返回 → 进度条从 0.9 走到 1.0 → 切回 home var panel = UIManager.Instance.Get(gamePanel); if (panel != null) { - panel.UnLoadResourcesWithProgress(() => - { - // 进度条加载完成后进入 home 界面 - UIManager.Instance.ShowAsync(UIPanel.HomeMainPanel, gamePanel); - }); + panel.OnLeaveRoomResultReceived(gamePanel); } else { diff --git a/Assets/MyGame/aa/UI/Game/GameMainPanel_FishBase.cs b/Assets/MyGame/aa/UI/Game/GameMainPanel_FishBase.cs index 51757129a..39dc4290f 100644 --- a/Assets/MyGame/aa/UI/Game/GameMainPanel_FishBase.cs +++ b/Assets/MyGame/aa/UI/Game/GameMainPanel_FishBase.cs @@ -486,9 +486,9 @@ public class GameMainPanel_FishBase : GameMainPanel_Base btn_QueRen.onClick.RemoveAllListeners(); btn_QueRen.onClick.AddListener(() => { - // 确认:直接退出房间 - WebSocketSendList.LeaveRoom(GameManager.Instance.gameData.currRoomData.roomId, currSitData.user); - CancelLeaveCountdown(); + // 确认:关闭确认面板,发送离房请求 + 启动进度条卸载 + if (obj_DJSPanel != null) obj_DJSPanel.SetActive(false); + RequestLeaveRoom(); }); } if (btn_QuXiao != null) @@ -783,19 +783,45 @@ public class GameMainPanel_FishBase : GameMainPanel_Base /// 资源是否已卸载(避免 OnHide 重复卸载) private bool _resourcesUnloaded = false; + /// 离房 socket 响应等待信号 + private TaskCompletionSource _leaveRoomResponseTcs; + /// 正在离开的游戏面板类型(完成后关闭它切到 home) + private UIPanel _leavingGamePanelType; + /// - /// 带进度条的卸载流程(复用加入游戏时的 JinDuTiao 进度条)。 - /// 卸载完成 + 末尾2秒等待后回调 onComplete,由调用方切换到 home 界面。 + /// 请求离开房间:发送离房 socket 请求 + 启动进度条卸载资源。 + /// 进度条走到 0.9 后等待 socket 返回 LeaveRoomResult, + /// 收到返回后走完剩余进度并切回 home 界面。 /// - public async void UnLoadResourcesWithProgress(Action onComplete = null) + public void RequestLeaveRoom() + { + if (_leaveRoomResponseTcs != null) return; // 防重复请求 + + // 先创建等待信号(在发送请求前创建,避免响应太快丢失) + _leaveRoomResponseTcs = new TaskCompletionSource(); + + // 发送离房请求 + WebSocketSendList.LeaveRoom( + GameManager.Instance.gameData.currRoomData.roomId, + currSitData.user); + //CreateFishManager.Instance.fangzhu = false; + + // 启动带进度条的卸载流程 + BeginLeaveRoomUnload(); + } + + /// + /// 离房卸载流程:进度条到 0.9 后等待 socket 响应, + /// 收到信号后走到 1.0 并切回 home 界面。 + /// + private async void BeginLeaveRoomUnload() { if (_resourcesUnloaded) { - onComplete?.Invoke(); + _leaveRoomResponseTcs = null; return; } - // ⭐ 复用加入游戏时的进度条 JinDuTiao.Show(); JinDuTiao.SetProgress(0.2f); @@ -817,8 +843,31 @@ public class GameMainPanel_FishBase : GameMainPanel_Base EffectPool.Instance.ClearAll(); JinDuTiao.SetProgress(0.9f); - // ⭐ 最后2秒留着(和加入游戏流程一致) - await Task.Delay(2000); + // ⭐ 卡在 0.9 等待 socket 返回 LeaveRoomResult + // - socket 已早返回(比卸载快) → 在 0.9 再等 1 秒(美观)后变 1 + // - socket 未返回 → 等待 socket,最多 10 秒,超时强制变 1 退出 + if (_leaveRoomResponseTcs != null) + { + bool alreadyReceived = _leaveRoomResponseTcs.Task.IsCompleted; + if (alreadyReceived) + { + // socket 比卸载早返回 → 0.9 停留 1 秒 + await Task.Delay(1000); + } + else + { + // socket 未返回 → 等待,最多 10 秒 + var timeoutTask = Task.Delay(10000); + var done = await Task.WhenAny(_leaveRoomResponseTcs.Task, timeoutTask); + if (done == timeoutTask) + { + // 超时 10 秒 → 强制退出,不管结算是否返回 +#if UNITY_EDITOR + Debug.LogWarning("[LeaveRoom] 等待 socket 超时 10 秒,强制退出"); +#endif + } + } + } // 标记已卸载,OnHide 跳过重复卸载 _resourcesUnloaded = true; @@ -827,7 +876,19 @@ public class GameMainPanel_FishBase : GameMainPanel_Base await Task.Delay(300); JinDuTiao.Hide(); - onComplete?.Invoke(); + // 进入 home 界面(关闭当前游戏面板) + UIManager.Instance.ShowAsync(UIPanel.HomeMainPanel, _leavingGamePanelType); + + _leaveRoomResponseTcs = null; + } + + /// + /// socket 收到 LeaveRoomResult 后调用,解除 0.9 的等待。 + /// + public void OnLeaveRoomResultReceived(UIPanel gamePanel) + { + _leavingGamePanelType = gamePanel; + _leaveRoomResponseTcs?.TrySetResult(true); } #endregion @@ -2430,7 +2491,7 @@ public class GameMainPanel_FishBase : GameMainPanel_Base public void TuiChuHHWK() { - WebSocketSendList.LeaveRoom(GameManager.Instance.gameData.currRoomData.roomId, currSitData.user); + RequestLeaveRoom(); } #endregion