Revert "fix: NetworkManagerHUD use NetworkManager.singleton"

This reverts commit 294011803b.
This commit is contained in:
vis2k 2022-01-05 17:56:53 +08:00
parent d17f91c447
commit eff3687a19

View File

@ -11,9 +11,16 @@ namespace Mirror
[HelpURL("https://mirror-networking.gitbook.io/docs/components/network-manager-hud")] [HelpURL("https://mirror-networking.gitbook.io/docs/components/network-manager-hud")]
public class NetworkManagerHUD : MonoBehaviour public class NetworkManagerHUD : MonoBehaviour
{ {
NetworkManager manager;
public int offsetX; public int offsetX;
public int offsetY; public int offsetY;
void Awake()
{
manager = GetComponent<NetworkManager>();
}
void OnGUI() void OnGUI()
{ {
GUILayout.BeginArea(new Rect(10 + offsetX, 40 + offsetY, 215, 9999)); GUILayout.BeginArea(new Rect(10 + offsetX, 40 + offsetY, 215, 9999));
@ -53,7 +60,7 @@ void StartButtons()
{ {
if (GUILayout.Button("Host (Server + Client)")) if (GUILayout.Button("Host (Server + Client)"))
{ {
NetworkManager.singleton.StartHost(); manager.StartHost();
} }
} }
@ -61,10 +68,10 @@ void StartButtons()
GUILayout.BeginHorizontal(); GUILayout.BeginHorizontal();
if (GUILayout.Button("Client")) if (GUILayout.Button("Client"))
{ {
NetworkManager.singleton.StartClient(); manager.StartClient();
} }
// This updates networkAddress every frame from the TextField // This updates networkAddress every frame from the TextField
NetworkManager.singleton.networkAddress = GUILayout.TextField(NetworkManager.singleton.networkAddress); manager.networkAddress = GUILayout.TextField(manager.networkAddress);
GUILayout.EndHorizontal(); GUILayout.EndHorizontal();
// Server Only // Server Only
@ -75,16 +82,16 @@ void StartButtons()
} }
else else
{ {
if (GUILayout.Button("Server Only")) NetworkManager.singleton.StartServer(); if (GUILayout.Button("Server Only")) manager.StartServer();
} }
} }
else else
{ {
// Connecting // Connecting
GUILayout.Label($"Connecting to {NetworkManager.singleton.networkAddress}.."); GUILayout.Label($"Connecting to {manager.networkAddress}..");
if (GUILayout.Button("Cancel Connection Attempt")) if (GUILayout.Button("Cancel Connection Attempt"))
{ {
NetworkManager.singleton.StopClient(); manager.StopClient();
} }
} }
} }
@ -107,7 +114,7 @@ void StatusLabels()
// client only // client only
else if (NetworkClient.isConnected) else if (NetworkClient.isConnected)
{ {
GUILayout.Label($"<b>Client</b>: connected to {NetworkManager.singleton.networkAddress} via {Transport.activeTransport}"); GUILayout.Label($"<b>Client</b>: connected to {manager.networkAddress} via {Transport.activeTransport}");
} }
} }
@ -118,7 +125,7 @@ void StopButtons()
{ {
if (GUILayout.Button("Stop Host")) if (GUILayout.Button("Stop Host"))
{ {
NetworkManager.singleton.StopHost(); manager.StopHost();
} }
} }
// stop client if client-only // stop client if client-only
@ -126,7 +133,7 @@ void StopButtons()
{ {
if (GUILayout.Button("Stop Client")) if (GUILayout.Button("Stop Client"))
{ {
NetworkManager.singleton.StopClient(); manager.StopClient();
} }
} }
// stop server if server-only // stop server if server-only
@ -134,7 +141,7 @@ void StopButtons()
{ {
if (GUILayout.Button("Stop Server")) if (GUILayout.Button("Stop Server"))
{ {
NetworkManager.singleton.StopServer(); manager.StopServer();
} }
} }
} }