From eff3687a195c95eefdc03022c73f60af2b8f0d41 Mon Sep 17 00:00:00 2001 From: vis2k Date: Wed, 5 Jan 2022 17:56:53 +0800 Subject: [PATCH] Revert "fix: NetworkManagerHUD use NetworkManager.singleton" This reverts commit 294011803bd7b96863006203d05026fca3a5fa52. --- Assets/Mirror/Runtime/NetworkManagerHUD.cs | 27 ++++++++++++++-------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/Assets/Mirror/Runtime/NetworkManagerHUD.cs b/Assets/Mirror/Runtime/NetworkManagerHUD.cs index b27178578..95a629598 100644 --- a/Assets/Mirror/Runtime/NetworkManagerHUD.cs +++ b/Assets/Mirror/Runtime/NetworkManagerHUD.cs @@ -11,9 +11,16 @@ namespace Mirror [HelpURL("https://mirror-networking.gitbook.io/docs/components/network-manager-hud")] public class NetworkManagerHUD : MonoBehaviour { + NetworkManager manager; + public int offsetX; public int offsetY; + void Awake() + { + manager = GetComponent(); + } + void OnGUI() { GUILayout.BeginArea(new Rect(10 + offsetX, 40 + offsetY, 215, 9999)); @@ -53,7 +60,7 @@ void StartButtons() { if (GUILayout.Button("Host (Server + Client)")) { - NetworkManager.singleton.StartHost(); + manager.StartHost(); } } @@ -61,10 +68,10 @@ void StartButtons() GUILayout.BeginHorizontal(); if (GUILayout.Button("Client")) { - NetworkManager.singleton.StartClient(); + manager.StartClient(); } // This updates networkAddress every frame from the TextField - NetworkManager.singleton.networkAddress = GUILayout.TextField(NetworkManager.singleton.networkAddress); + manager.networkAddress = GUILayout.TextField(manager.networkAddress); GUILayout.EndHorizontal(); // Server Only @@ -75,16 +82,16 @@ void StartButtons() } else { - if (GUILayout.Button("Server Only")) NetworkManager.singleton.StartServer(); + if (GUILayout.Button("Server Only")) manager.StartServer(); } } else { // Connecting - GUILayout.Label($"Connecting to {NetworkManager.singleton.networkAddress}.."); + GUILayout.Label($"Connecting to {manager.networkAddress}.."); if (GUILayout.Button("Cancel Connection Attempt")) { - NetworkManager.singleton.StopClient(); + manager.StopClient(); } } } @@ -107,7 +114,7 @@ void StatusLabels() // client only else if (NetworkClient.isConnected) { - GUILayout.Label($"Client: connected to {NetworkManager.singleton.networkAddress} via {Transport.activeTransport}"); + GUILayout.Label($"Client: connected to {manager.networkAddress} via {Transport.activeTransport}"); } } @@ -118,7 +125,7 @@ void StopButtons() { if (GUILayout.Button("Stop Host")) { - NetworkManager.singleton.StopHost(); + manager.StopHost(); } } // stop client if client-only @@ -126,7 +133,7 @@ void StopButtons() { if (GUILayout.Button("Stop Client")) { - NetworkManager.singleton.StopClient(); + manager.StopClient(); } } // stop server if server-only @@ -134,7 +141,7 @@ void StopButtons() { if (GUILayout.Button("Stop Server")) { - NetworkManager.singleton.StopServer(); + manager.StopServer(); } } }