Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions Assets/Mirror/Components/NetworkPingDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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 = $"[<color=#{litColor}>{lit}</color><color=#{unlitColor}>{unlit}</color>]";
GUILayout.Label($"RTT: {rttMs} ms");
GUILayout.Label($"Q: {bar}");

GUILayout.EndHorizontal();
GUILayout.EndArea();
GUI.color = Color.white;
Expand Down