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
This commit is contained in:
MrGadget 2019-02-24 14:31:13 -05:00 committed by vis2k
parent cda1240444
commit 4a59f563e0
8 changed files with 19 additions and 21 deletions

View File

@ -68,6 +68,7 @@ internal void ReadyStatusChanged()
{ {
int CurrentPlayers = 0; int CurrentPlayers = 0;
int ReadyPlayers = 0; int ReadyPlayers = 0;
foreach (NetworkLobbyPlayer item in lobbySlots) foreach (NetworkLobbyPlayer item in lobbySlots)
{ {
if (item != null) if (item != null)
@ -77,6 +78,7 @@ internal void ReadyStatusChanged()
ReadyPlayers++; ReadyPlayers++;
} }
} }
if (CurrentPlayers == ReadyPlayers) if (CurrentPlayers == ReadyPlayers)
CheckReadyToBegin(); CheckReadyToBegin();
else else

View File

@ -25,10 +25,7 @@ public void Start()
if (isClient) SceneManager.sceneLoaded += ClientLoadedScene; if (isClient) SceneManager.sceneLoaded += ClientLoadedScene;
if (NetworkManager.singleton as NetworkLobbyManager) if (NetworkManager.singleton as NetworkLobbyManager)
{
ReadyToBegin = false;
OnClientEnterLobby(); OnClientEnterLobby();
}
else 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."); 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; SceneManager.sceneLoaded -= ClientLoadedScene;
} }
void ClientLoadedScene(Scene arg0, LoadSceneMode arg1) public virtual void ClientLoadedScene(Scene arg0, LoadSceneMode arg1)
{ {
NetworkLobbyManager lobby = NetworkManager.singleton as NetworkLobbyManager; NetworkLobbyManager lobby = NetworkManager.singleton as NetworkLobbyManager;
if (lobby && SceneManager.GetActiveScene().name == lobby.LobbyScene) if (lobby != null && SceneManager.GetActiveScene().name == lobby.LobbyScene)
return; return;
if (this != null && isLocalPlayer) if (this != null && isLocalPlayer)
@ -130,4 +127,4 @@ public virtual void OnGUI()
#endregion #endregion
} }
} }

View File

@ -320,7 +320,7 @@ MonoBehaviour:
playerPrefab: {fileID: 1480027675339556, guid: 21daf89214c6ee443ad6875b73083c60, playerPrefab: {fileID: 1480027675339556, guid: 21daf89214c6ee443ad6875b73083c60,
type: 3} type: 3}
autoCreatePlayer: 1 autoCreatePlayer: 1
playerSpawnMethod: 0 playerSpawnMethod: 1
spawnPrefabs: spawnPrefabs:
- {fileID: 1139254171913846, guid: 52f1c9ea06cfd154cb68ff9d1b66fc13, type: 3} - {fileID: 1139254171913846, guid: 52f1c9ea06cfd154cb68ff9d1b66fc13, type: 3}
showLobbyGUI: 1 showLobbyGUI: 1

View File

@ -1,4 +1,4 @@
using UnityEngine; using UnityEngine;
using Mirror; using Mirror;
using UnityEngine.SceneManagement; using UnityEngine.SceneManagement;
@ -24,18 +24,24 @@ This demonstrates how to set the parent of the LobbyPlayerPrefab to an arbitrary
in ServerChangeScene and OnClientChangeScene. 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); 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() 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() public override void OnClientExitLobby()
{ {
Debug.LogFormat("OnClientExitLobby {0}", SceneManager.GetActiveScene().name); if (LogFilter.Debug) Debug.LogFormat("OnClientExitLobby {0}", SceneManager.GetActiveScene().name);
} }
} }
} }

View File

@ -1,4 +1,4 @@
using UnityEngine; using UnityEngine;
using UnityEngine.SceneManagement; using UnityEngine.SceneManagement;
namespace Mirror.Examples.NetworkLobby namespace Mirror.Examples.NetworkLobby
@ -12,9 +12,6 @@ void Start()
{ {
// Ensure main camera is enabled because it will be disabled by PlayerController // Ensure main camera is enabled because it will be disabled by PlayerController
Camera.main.enabled = true; 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() void OnGUI()
@ -25,9 +22,7 @@ void OnGUI()
GUILayout.Box("WASDQE keys to move & turn\nTouch the spheres for points\nLighter colors score higher"); GUILayout.Box("WASDQE keys to move & turn\nTouch the spheres for points\nLighter colors score higher");
if (GUILayout.Button("Join Game")) if (GUILayout.Button("Join Game"))
{
SceneManager.LoadScene(LobbyScene); SceneManager.LoadScene(LobbyScene);
}
GUILayout.EndArea(); GUILayout.EndArea();
} }

View File

@ -41,7 +41,6 @@ public override void OnStartLocalPlayer()
void SetColor(Color color) void SetColor(Color color)
{ {
//Debug.LogWarningFormat("PlayerController SetColor netId:{0} to {1}", netId, color);
GetComponent<Renderer>().material.color = color; GetComponent<Renderer>().material.color = color;
} }
@ -102,7 +101,6 @@ void OnControllerColliderHit(ControllerColliderHit hit)
public void CmdClaimPrize(GameObject hitObject) public void CmdClaimPrize(GameObject hitObject)
{ {
// Null check is required, otherwise close timing of multiple claims could throw a null ref. // Null check is required, otherwise close timing of multiple claims could throw a null ref.
//if (hitObject != null)
hitObject?.GetComponent<Reward>().ClaimPrize(gameObject); hitObject?.GetComponent<Reward>().ClaimPrize(gameObject);
} }

View File

@ -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._ _Note: Mirror is based on Unity's abandoned UNET Networking system. We fixed it up and pushed it to MMO Scale._
## Documentation ## 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. The main difference is that you have to use `using Mirror;` instead of `using UnityEngine.Networking;` at the top of your scripts.

View File

@ -13,7 +13,7 @@ NetworkDiscovery was a UNet component intended for UDP projects. Since Mirror w
## networkPort in Network Manager ## 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 ## Couch Co-Op