diff --git a/Assets/Mirror/Components/NetworkPingDisplay.cs b/Assets/Mirror/Components/NetworkPingDisplay.cs index a45ced5b2b..85a0a8fd87 100644 --- a/Assets/Mirror/Components/NetworkPingDisplay.cs +++ b/Assets/Mirror/Components/NetworkPingDisplay.cs @@ -15,6 +15,10 @@ public class NetworkPingDisplay : MonoBehaviour public int padding = 2; public int width = 150; public int height = 25; + + [Header("Bar Character")] + [Tooltip("Character to represent filled segments of the connection quality bar")] + public char barChar = '■'; #if !UNITY_SERVER || UNITY_EDITOR void OnGUI() @@ -28,10 +32,25 @@ void OnGUI() GUILayout.BeginArea(rect); GUIStyle style = GUI.skin.GetStyle("Label"); style.alignment = TextAnchor.MiddleRight; + style.richText = true; // enable colored substrings + GUILayout.BeginHorizontal(style); - GUILayout.Label($"RTT: {Math.Round(NetworkTime.rtt * 1000)}ms"); - GUI.color = NetworkClient.connectionQuality.ColorCode(); - GUILayout.Label($"Q: {new string('-', (int)NetworkClient.connectionQuality)}"); + + double rttMs = Math.Round(NetworkTime.rtt * 1000); + var quality = NetworkClient.connectionQuality; + int totalSegments = Enum.GetValues(typeof(ConnectionQuality)).Length - 1; + int filled = Mathf.Clamp((int)quality, 0, totalSegments); + + string lit = new string(barChar, filled); + string unlit = new string(barChar, totalSegments - filled); + string litColor = ColorUtility.ToHtmlStringRGB(quality.ColorCode()); + string unlitColor = "666666"; + + // Q: [■■■■] (lit part colored, unlit part grey) + string bar = $"[{lit}{unlit}]"; + GUILayout.Label($"RTT: {rttMs} ms"); + GUILayout.Label($"Q: {bar}"); + GUILayout.EndHorizontal(); GUILayout.EndArea(); GUI.color = Color.white;