From 4a59f563e061ae361e29e43c7de2b233235cbde7 Mon Sep 17 00:00:00 2001 From: MrGadget Date: Sun, 24 Feb 2019 14:31:13 -0500 Subject: [PATCH] Network Lobby Updates (#438) * Fixed 1 link to be relative Removed Wiki link from ReadMe * Made ClientLoadedScene virtual Updates to scene object references Scene and vsync handling improvements Minor cleanup. * removed all use of vSyncCount * Fixed bug with ReadyToBegin being incorrectly set --- Assets/Mirror/Components/NetworkLobbyManager.cs | 2 ++ Assets/Mirror/Components/NetworkLobbyPlayer.cs | 9 +++------ .../Mirror/Examples/Lobby/Scenes/LobbyScene.unity | 2 +- .../Lobby/Scripts/NetworkLobbyPlayerExt.cs | 14 ++++++++++---- Assets/Mirror/Examples/Lobby/Scripts/OfflineGUI.cs | 7 +------ .../Examples/Lobby/Scripts/PlayerController.cs | 2 -- README.md | 2 +- docs/General/Deprecations.md | 2 +- 8 files changed, 19 insertions(+), 21 deletions(-) diff --git a/Assets/Mirror/Components/NetworkLobbyManager.cs b/Assets/Mirror/Components/NetworkLobbyManager.cs index 52d8d98fd..58329a6ae 100644 --- a/Assets/Mirror/Components/NetworkLobbyManager.cs +++ b/Assets/Mirror/Components/NetworkLobbyManager.cs @@ -68,6 +68,7 @@ internal void ReadyStatusChanged() { int CurrentPlayers = 0; int ReadyPlayers = 0; + foreach (NetworkLobbyPlayer item in lobbySlots) { if (item != null) @@ -77,6 +78,7 @@ internal void ReadyStatusChanged() ReadyPlayers++; } } + if (CurrentPlayers == ReadyPlayers) CheckReadyToBegin(); else diff --git a/Assets/Mirror/Components/NetworkLobbyPlayer.cs b/Assets/Mirror/Components/NetworkLobbyPlayer.cs index e98d202ab..7bc831da1 100644 --- a/Assets/Mirror/Components/NetworkLobbyPlayer.cs +++ b/Assets/Mirror/Components/NetworkLobbyPlayer.cs @@ -25,10 +25,7 @@ public void Start() if (isClient) SceneManager.sceneLoaded += ClientLoadedScene; if (NetworkManager.singleton as NetworkLobbyManager) - { - ReadyToBegin = false; OnClientEnterLobby(); - } else Debug.LogError("LobbyPlayer could not find a NetworkLobbyManager. The LobbyPlayer requires a NetworkLobbyManager object to function. Make sure that there is one in the scene."); } @@ -38,10 +35,10 @@ void OnDisable() SceneManager.sceneLoaded -= ClientLoadedScene; } - void ClientLoadedScene(Scene arg0, LoadSceneMode arg1) + public virtual void ClientLoadedScene(Scene arg0, LoadSceneMode arg1) { NetworkLobbyManager lobby = NetworkManager.singleton as NetworkLobbyManager; - if (lobby && SceneManager.GetActiveScene().name == lobby.LobbyScene) + if (lobby != null && SceneManager.GetActiveScene().name == lobby.LobbyScene) return; if (this != null && isLocalPlayer) @@ -130,4 +127,4 @@ public virtual void OnGUI() #endregion } -} \ No newline at end of file +} diff --git a/Assets/Mirror/Examples/Lobby/Scenes/LobbyScene.unity b/Assets/Mirror/Examples/Lobby/Scenes/LobbyScene.unity index 2cdbb3d28..0b154404e 100644 --- a/Assets/Mirror/Examples/Lobby/Scenes/LobbyScene.unity +++ b/Assets/Mirror/Examples/Lobby/Scenes/LobbyScene.unity @@ -320,7 +320,7 @@ MonoBehaviour: playerPrefab: {fileID: 1480027675339556, guid: 21daf89214c6ee443ad6875b73083c60, type: 3} autoCreatePlayer: 1 - playerSpawnMethod: 0 + playerSpawnMethod: 1 spawnPrefabs: - {fileID: 1139254171913846, guid: 52f1c9ea06cfd154cb68ff9d1b66fc13, type: 3} showLobbyGUI: 1 diff --git a/Assets/Mirror/Examples/Lobby/Scripts/NetworkLobbyPlayerExt.cs b/Assets/Mirror/Examples/Lobby/Scripts/NetworkLobbyPlayerExt.cs index c73592326..18aebe66b 100644 --- a/Assets/Mirror/Examples/Lobby/Scripts/NetworkLobbyPlayerExt.cs +++ b/Assets/Mirror/Examples/Lobby/Scripts/NetworkLobbyPlayerExt.cs @@ -1,4 +1,4 @@ -using UnityEngine; +using UnityEngine; using Mirror; using UnityEngine.SceneManagement; @@ -24,18 +24,24 @@ This demonstrates how to set the parent of the LobbyPlayerPrefab to an arbitrary in ServerChangeScene and OnClientChangeScene. */ - if (lobby && lobby.LobbyScene == SceneManager.GetActiveScene().name) + if (lobby != null && SceneManager.GetActiveScene().name == lobby.LobbyScene) gameObject.transform.SetParent(GameObject.Find("Players").transform); } + public override void ClientLoadedScene(Scene arg0, LoadSceneMode arg1) + { + NetworkLobbyManager lobby = NetworkManager.singleton as NetworkLobbyManager; + base.ClientLoadedScene(arg0, arg1); + } + public override void OnClientEnterLobby() { - Debug.LogFormat("OnClientEnterLobby {0}", SceneManager.GetActiveScene().name); + if (LogFilter.Debug) Debug.LogFormat("OnClientEnterLobby {0}", SceneManager.GetActiveScene().name); } public override void OnClientExitLobby() { - Debug.LogFormat("OnClientExitLobby {0}", SceneManager.GetActiveScene().name); + if (LogFilter.Debug) Debug.LogFormat("OnClientExitLobby {0}", SceneManager.GetActiveScene().name); } } } diff --git a/Assets/Mirror/Examples/Lobby/Scripts/OfflineGUI.cs b/Assets/Mirror/Examples/Lobby/Scripts/OfflineGUI.cs index 505e5ac8a..bde1ca3b4 100644 --- a/Assets/Mirror/Examples/Lobby/Scripts/OfflineGUI.cs +++ b/Assets/Mirror/Examples/Lobby/Scripts/OfflineGUI.cs @@ -1,4 +1,4 @@ -using UnityEngine; +using UnityEngine; using UnityEngine.SceneManagement; namespace Mirror.Examples.NetworkLobby @@ -12,9 +12,6 @@ void Start() { // Ensure main camera is enabled because it will be disabled by PlayerController Camera.main.enabled = true; - - // Since this is a UI only screen, lower the framerate and thereby lower the CPU load - Application.targetFrameRate = 10; } void OnGUI() @@ -25,9 +22,7 @@ void OnGUI() GUILayout.Box("WASDQE keys to move & turn\nTouch the spheres for points\nLighter colors score higher"); if (GUILayout.Button("Join Game")) - { SceneManager.LoadScene(LobbyScene); - } GUILayout.EndArea(); } diff --git a/Assets/Mirror/Examples/Lobby/Scripts/PlayerController.cs b/Assets/Mirror/Examples/Lobby/Scripts/PlayerController.cs index 4f52cafdf..ef032df40 100644 --- a/Assets/Mirror/Examples/Lobby/Scripts/PlayerController.cs +++ b/Assets/Mirror/Examples/Lobby/Scripts/PlayerController.cs @@ -41,7 +41,6 @@ public override void OnStartLocalPlayer() void SetColor(Color color) { - //Debug.LogWarningFormat("PlayerController SetColor netId:{0} to {1}", netId, color); GetComponent().material.color = color; } @@ -102,7 +101,6 @@ void OnControllerColliderHit(ControllerColliderHit hit) public void CmdClaimPrize(GameObject hitObject) { // Null check is required, otherwise close timing of multiple claims could throw a null ref. - //if (hitObject != null) hitObject?.GetComponent().ClaimPrize(gameObject); } diff --git a/README.md b/README.md index 90f9f513a..45691df8b 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ What previously required **10.000** lines of code, now takes **1.000** lines of _Note: Mirror is based on Unity's abandoned UNET Networking system. We fixed it up and pushed it to MMO Scale._ ## Documentation -Check out our [Documentation](https://vis2k.github.io/Mirror/) and read the [Wiki](https://github.com/vis2k/Mirror/wiki). +Check out our [Documentation](https://vis2k.github.io/Mirror/). The main difference is that you have to use `using Mirror;` instead of `using UnityEngine.Networking;` at the top of your scripts. diff --git a/docs/General/Deprecations.md b/docs/General/Deprecations.md index df9f41b1e..1da62f5c8 100644 --- a/docs/General/Deprecations.md +++ b/docs/General/Deprecations.md @@ -13,7 +13,7 @@ NetworkDiscovery was a UNet component intended for UDP projects. Since Mirror w ## networkPort in Network Manager -Network Manager's `networkPort` property was removed now that all transports are separate components. Not all transports use ports, but those that do have a field for it. See [Transports](https://vis2k.github.io/Mirror/Transports) for more info. +Network Manager's `networkPort` property was removed now that all transports are separate components. Not all transports use ports, but those that do have a field for it. See [Transports](../Transports) for more info. ## Couch Co-Op