1
This commit is contained in:
Binary file not shown.
@@ -24,9 +24,9 @@ namespace Assets.MyGame.Scripts.Net
|
||||
public const string baseURL = "http://47.109.132.12";
|
||||
|
||||
#else
|
||||
//public const string baseURL = "http://47.109.132.12";
|
||||
public const string baseURL = "http://47.109.132.12";
|
||||
|
||||
public const string baseURL = "http://47.109.34.50";
|
||||
//public const string baseURL = "http://47.109.34.50";
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -38,9 +38,9 @@ namespace Assets.MyGame.Scripts.Net
|
||||
private const string baseUrl = "ws://47.109.132.12";
|
||||
|
||||
#else
|
||||
//private const string baseUrl = "ws://47.109.132.12";
|
||||
private const string baseUrl = "ws://47.109.132.12";
|
||||
|
||||
private const string baseUrl = "ws://47.109.34.50";
|
||||
//private const string baseUrl = "ws://47.109.34.50";
|
||||
|
||||
#endif
|
||||
public bool isGame = false;
|
||||
|
||||
@@ -529,8 +529,7 @@ namespace Assets.MyGame.Scripts.Net
|
||||
/// 统一退出捕鱼游戏流程:
|
||||
/// 1. 关闭 game socket(自己的离房通知已收到,可以正常关闭)
|
||||
/// 2. 拉取最新用户数据并触发 OnUserDataChanged 事件,同步大厅金币/钻石/等级等 UI
|
||||
/// 3. 复用游戏内 JinDuTiao 进度条卸载资源(和加入游戏流程一致,末尾保留2秒)
|
||||
/// 4. 进度条完成后切回大厅
|
||||
/// 3. 通知游戏面板 socket 已返回 → 解除进度条 0.9 的等待 → 走完剩余进度后自动切回 home
|
||||
/// </summary>
|
||||
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<GameMainPanel_FishBase>(gamePanel);
|
||||
if (panel != null)
|
||||
{
|
||||
panel.UnLoadResourcesWithProgress(() =>
|
||||
{
|
||||
// 进度条加载完成后进入 home 界面
|
||||
UIManager.Instance.ShowAsync(UIPanel.HomeMainPanel, gamePanel);
|
||||
});
|
||||
panel.OnLeaveRoomResultReceived(gamePanel);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -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
|
||||
/// <summary>资源是否已卸载(避免 OnHide 重复卸载)</summary>
|
||||
private bool _resourcesUnloaded = false;
|
||||
|
||||
/// <summary>离房 socket 响应等待信号</summary>
|
||||
private TaskCompletionSource<bool> _leaveRoomResponseTcs;
|
||||
/// <summary>正在离开的游戏面板类型(完成后关闭它切到 home)</summary>
|
||||
private UIPanel _leavingGamePanelType;
|
||||
|
||||
/// <summary>
|
||||
/// 带进度条的卸载流程(复用加入游戏时的 JinDuTiao 进度条)。
|
||||
/// 卸载完成 + 末尾2秒等待后回调 onComplete,由调用方切换到 home 界面。
|
||||
/// 请求离开房间:发送离房 socket 请求 + 启动进度条卸载资源。
|
||||
/// 进度条走到 0.9 后等待 socket 返回 LeaveRoomResult,
|
||||
/// 收到返回后走完剩余进度并切回 home 界面。
|
||||
/// </summary>
|
||||
public async void UnLoadResourcesWithProgress(Action onComplete = null)
|
||||
public void RequestLeaveRoom()
|
||||
{
|
||||
if (_leaveRoomResponseTcs != null) return; // 防重复请求
|
||||
|
||||
// 先创建等待信号(在发送请求前创建,避免响应太快丢失)
|
||||
_leaveRoomResponseTcs = new TaskCompletionSource<bool>();
|
||||
|
||||
// 发送离房请求
|
||||
WebSocketSendList.LeaveRoom(
|
||||
GameManager.Instance.gameData.currRoomData.roomId,
|
||||
currSitData.user);
|
||||
//CreateFishManager.Instance.fangzhu = false;
|
||||
|
||||
// 启动带进度条的卸载流程
|
||||
BeginLeaveRoomUnload();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 离房卸载流程:进度条到 0.9 后等待 socket 响应,
|
||||
/// 收到信号后走到 1.0 并切回 home 界面。
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// socket 收到 LeaveRoomResult 后调用,解除 0.9 的等待。
|
||||
/// </summary>
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user