final feedbacks fixed
This commit is contained in:
@@ -1,11 +1,72 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using Mirror;
|
||||
|
||||
public class NetManager : NetworkManager
|
||||
{
|
||||
[SerializeField] float reconnectIntervalSeconds = 15f;
|
||||
Coroutine reconnectCoroutine;
|
||||
|
||||
public override void OnStopServer()
|
||||
{
|
||||
GameManager.ReportDedicatedMatchRoomClosed();
|
||||
base.OnStopServer();
|
||||
}
|
||||
|
||||
public override void OnStopClient()
|
||||
{
|
||||
base.OnStopClient();
|
||||
TryStartReconnectLoop();
|
||||
}
|
||||
|
||||
public override void OnClientConnect()
|
||||
{
|
||||
base.OnClientConnect();
|
||||
StopReconnectLoop();
|
||||
}
|
||||
|
||||
void TryStartReconnectLoop()
|
||||
{
|
||||
if (!ShouldReconnect() || reconnectCoroutine != null)
|
||||
return;
|
||||
|
||||
reconnectCoroutine = StartCoroutine(CoroutineReconnectLoop());
|
||||
}
|
||||
|
||||
void StopReconnectLoop()
|
||||
{
|
||||
if (reconnectCoroutine == null)
|
||||
return;
|
||||
|
||||
StopCoroutine(reconnectCoroutine);
|
||||
reconnectCoroutine = null;
|
||||
}
|
||||
|
||||
bool ShouldReconnect()
|
||||
{
|
||||
if (NetworkServer.active)
|
||||
return false;
|
||||
if (NetworkClient.isConnected)
|
||||
return false;
|
||||
if (GameManager.instance != null && GameManager.instance.isGameEnded)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
IEnumerator CoroutineReconnectLoop()
|
||||
{
|
||||
while (ShouldReconnect())
|
||||
{
|
||||
if (!NetworkClient.active)
|
||||
{
|
||||
Debug.Log("Client disconnected. Reconnecting...");
|
||||
StartClient();
|
||||
}
|
||||
|
||||
yield return new WaitForSeconds(reconnectIntervalSeconds);
|
||||
}
|
||||
|
||||
reconnectCoroutine = null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user