网络等待新增超时参数

main
Yuntao Hu 2025-03-26 13:33:20 +08:00
parent 392c0bf348
commit fa39f8ff6f
1 changed files with 20 additions and 2 deletions

View File

@ -71,6 +71,21 @@ public class WaitingForServer : Singlenton<WaitingForServer>, IInitable, IUpdata
}
}
async void HandleTimeout(EventName eventName, float timeout)
{
await UniTask.WaitForSeconds(timeout);
if (Events.Contains(eventName))
{
Events.Remove(eventName);
DebugUtil.Log("EventWaiting Timeout:" + eventName.ToString());
if (Events.Count == 0)
{
_isLoading = false;
UINetManager.Instance.HideReconnect();
}
}
}
#endregion
/// <summary>
@ -107,9 +122,10 @@ public class WaitingForServer : Singlenton<WaitingForServer>, IInitable, IUpdata
/// 网络事件等待
/// </summary>
/// <param name="eventName">注册事件名称</param>
/// <param name="needPrepare">是否需要等待预备</param>
/// <param name="needPrepare">是否需要等待预备,等待预备时间为1秒</param>
/// <param name="needCoolDown">冷却队列,使得短时间内同样的网络事件请求不会重复拉起转圈</param>
public void EventWaiting(EventName eventName, bool needPrepare = true, bool needCoolDown = true)
/// <param name="timeout">超时时间</param>
public void EventWaiting(EventName eventName, bool needPrepare = false, bool needCoolDown = true, float timeout = -1f)
{
if (Events.Contains(eventName))
{
@ -131,6 +147,8 @@ public class WaitingForServer : Singlenton<WaitingForServer>, IInitable, IUpdata
UINetManager.Instance.ShowReconnect();
}
}
if (timeout > 0)
HandleTimeout(eventName, timeout);
}
public void EventDone(EventName eventName)