diff --git a/Assets/Scripts/Networking/CustomNetworkManager.cs b/Assets/Scripts/Networking/CustomNetworkManager.cs new file mode 100644 index 00000000..3a637543 --- /dev/null +++ b/Assets/Scripts/Networking/CustomNetworkManager.cs @@ -0,0 +1,74 @@ +using System.Collections.Generic; +using UnityEngine; +using Mirror; +using SanAndreasUnity.Utilities; +using SanAndreasUnity.Behaviours; + +namespace SanAndreasUnity.Net +{ + + public class CustomNetworkManager : NetworkManager + { + + public override void OnClientConnect(NetworkConnection conn) + { + if (NetStatus.IsServer) + { + // just do default action + base.OnClientConnect(conn); + return; + } + + // default method: if no scene was loaded, do Ready/AddPlayer + + // we won't do this until loading process finishes + + if (Loader.HasLoaded) + base.OnClientConnect(conn); + } + + public override void OnClientSceneChanged(NetworkConnection conn) + { + if (NetStatus.IsServer) + { + // just do default action + base.OnClientSceneChanged(conn); + return; + } + + // default method: do Ready/AddPlayer + + // we won't do this until loading process finishes + + if (Loader.HasLoaded) + base.OnClientSceneChanged(conn); + } + + void OnLoaderFinished() + { + if (NetStatus.IsServer) // don't do anything on server + return; + + if (!NetworkClient.isConnected) + { + // client is not connected ? hmm... then loading process could not have started + Debug.LogErrorFormat("Loader finished, but client is not connected"); + return; + } + + // make client ready + if (ClientScene.ready) + Debug.LogErrorFormat("Client was made ready before loader finished"); + else + ClientScene.Ready(NetworkClient.connection); + + // add player if specified + if (autoCreatePlayer && ClientScene.localPlayer == null) + { + ClientScene.AddPlayer(); + } + } + + } + +} diff --git a/Assets/Scripts/Networking/CustomNetworkManager.cs.meta b/Assets/Scripts/Networking/CustomNetworkManager.cs.meta new file mode 100644 index 00000000..fc396f6b --- /dev/null +++ b/Assets/Scripts/Networking/CustomNetworkManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 155a544cb11c9481ea41b4e39d8c4b3f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Docs/Multiplayer.md b/Docs/Multiplayer.md index 075e7ca4..6382c068 100644 --- a/Docs/Multiplayer.md +++ b/Docs/Multiplayer.md @@ -8,8 +8,6 @@ - send input to server -- make console available in main menu - - client must not be marked as ready, until Loader finishes