From fa7977f5ae201b6e47fb10c2feefa0e55334d054 Mon Sep 17 00:00:00 2001 From: mischa Date: Mon, 6 Nov 2023 10:15:55 +0100 Subject: [PATCH] feat: NetworkManagerHUD exposes configurable Port field if Transport uses a Port --- Assets/Mirror/Core/NetworkManagerHUD.cs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/Assets/Mirror/Core/NetworkManagerHUD.cs b/Assets/Mirror/Core/NetworkManagerHUD.cs index 0a267fb4e..06dcb172a 100644 --- a/Assets/Mirror/Core/NetworkManagerHUD.cs +++ b/Assets/Mirror/Core/NetworkManagerHUD.cs @@ -1,5 +1,3 @@ -// vis2k: GUILayout instead of spacey += ...; removed Update hotkeys to avoid -// confusion if someone accidentally presses one. using UnityEngine; namespace Mirror @@ -64,14 +62,26 @@ void StartButtons() } } - // Client + IP + // Client + IP (+ PORT) GUILayout.BeginHorizontal(); if (GUILayout.Button("Client")) { manager.StartClient(); } - // This updates networkAddress every frame from the TextField manager.networkAddress = GUILayout.TextField(manager.networkAddress); + // only show a port field if we have a port transport + // we can't have "IP:PORT" in the address field since this only + // works for IPV4:PORT. + // for IPV6:PORT it would be misleading since IPV6 contains ":": + // 2001:0db8:0000:0000:0000:ff00:0042:8329 + if (Transport.active is PortTransport portTransport) + { + // use TryParse in case someone tries to enter non-numeric characters + if (ushort.TryParse(GUILayout.TextField(portTransport.Port.ToString()), out ushort port)) + { + portTransport.Port = port; + } + } GUILayout.EndHorizontal(); // Server Only