feature: NetworkManager gentle offline scene transition after disconnect. allows studios to show a 'Connection Lost!' message for a few seconds before entering a potentially minute long black screen scene load (#3875)

Co-authored-by: mischa <info@noobtuts.com>
This commit is contained in:
mischa 2024-07-26 21:19:02 +02:00 committed by GitHub
parent 693a9999d6
commit bc9329a825
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -76,6 +76,9 @@ public class NetworkManager : MonoBehaviour
[Tooltip("Scene that Mirror will switch to when the server is started. Clients will recieve a Scene Message to load the server's current scene when they connect.")] [Tooltip("Scene that Mirror will switch to when the server is started. Clients will recieve a Scene Message to load the server's current scene when they connect.")]
public string onlineScene = ""; public string onlineScene = "";
[Tooltip("Optional delay that can be used after disconnecting to show a 'Connection lost...' message or similar before loading the offline scene, which may take a long time in big projects.")]
public float offlineSceneLoadDelaySeconds = 0;
// transport layer // transport layer
[Header("Network Info")] [Header("Network Info")]
[Tooltip("Transport component attached to this object that server and client will use to connect")] [Tooltip("Transport component attached to this object that server and client will use to connect")]
@ -1333,12 +1336,16 @@ void OnClientDisconnectInternal()
// Check if NetworkServer.active because we can get here via Disconnect before server has started to change scenes. // Check if NetworkServer.active because we can get here via Disconnect before server has started to change scenes.
if (!string.IsNullOrWhiteSpace(offlineScene) && !Utils.IsSceneActive(offlineScene) && loadingSceneAsync == null && !NetworkServer.active) if (!string.IsNullOrWhiteSpace(offlineScene) && !Utils.IsSceneActive(offlineScene) && loadingSceneAsync == null && !NetworkServer.active)
{ {
ClientChangeScene(offlineScene, SceneOperation.Normal); Invoke(nameof(ClientChangeOfflineScene), offlineSceneLoadDelaySeconds);
} }
networkSceneName = ""; networkSceneName = "";
} }
// wrap ClientChangeScene call without parameters for use in Invoke.
void ClientChangeOfflineScene() =>
ClientChangeScene(offlineScene, SceneOperation.Normal);
void OnClientNotReadyMessageInternal(NotReadyMessage msg) void OnClientNotReadyMessageInternal(NotReadyMessage msg)
{ {
//Debug.Log("NetworkManager.OnClientNotReadyMessageInternal"); //Debug.Log("NetworkManager.OnClientNotReadyMessageInternal");