replace with string builder

This commit is contained in:
in0finite 2022-04-21 17:46:39 +02:00
parent 959dff5204
commit 5c79529407

View file

@ -3,6 +3,7 @@ using UnityEngine;
using Mirror; using Mirror;
using SanAndreasUnity.Behaviours.Peds; using SanAndreasUnity.Behaviours.Peds;
using SanAndreasUnity.Net; using SanAndreasUnity.Net;
using System;
namespace SanAndreasUnity.Stats namespace SanAndreasUnity.Stats
{ {
@ -15,30 +16,39 @@ namespace SanAndreasUnity.Stats
void OnStatGUI() void OnStatGUI()
{ {
GUILayout.Label("Network time: " + NetworkTime.time); var sb = new System.Text.StringBuilder();
GUILayout.Label("Local network time: " + NetworkTime.localTime);
AddTimeSpan(sb, "Network time: ", NetworkTime.time);
AddTimeSpan(sb, "Local network time: ", NetworkTime.localTime);
if (NetStatus.IsServer) if (NetStatus.IsServer)
{ {
Utilities.GUIUtils.DrawHorizontalLine(1, 1, Color.black); sb.AppendLine("-----------------------");
GUILayout.Label("Num connections: " + NetworkServer.connections.Count); sb.AppendLine("Num connections: " + NetworkServer.connections.Count);
GUILayout.Label("Max num players: " + NetManager.maxNumPlayers); sb.AppendLine("Max num players: " + NetManager.maxNumPlayers);
GUILayout.Label($"Dead body traffic per client: {DeadBody.DeadBodies.Sum(db => db.TrafficKbps)} Kb/s"); sb.AppendLine($"Dead body traffic per client: {DeadBody.DeadBodies.Sum(db => db.TrafficKbps)} Kb/s");
} }
if (NetStatus.IsClientActive()) if (NetStatus.IsClientActive())
{ {
Utilities.GUIUtils.DrawHorizontalLine(1, 1, Color.black); sb.AppendLine("-----------------------");
GUILayout.Label("Ping: " + (NetworkTime.rtt * 1000) + " ms"); sb.AppendLine("Ping: " + (NetworkTime.rtt * 1000) + " ms");
GUILayout.Label("Ping send frequency: " + (NetworkTime.PingFrequency * 1000) + " ms"); sb.AppendLine("Ping send frequency: " + (NetworkTime.PingFrequency * 1000) + " ms");
GUILayout.Label("Rtt sd: " + (NetworkTime.rttStandardDeviation * 1000) + " ms"); sb.AppendLine("Rtt sd: " + (NetworkTime.rttStandardDeviation * 1000) + " ms");
GUILayout.Label("Rtt var: " + (NetworkTime.rttVariance * 1000) + " ms"); sb.AppendLine("Rtt var: " + (NetworkTime.rttVariance * 1000) + " ms");
GUILayout.Label("Server ip: " + NetworkClient.serverIp); sb.AppendLine("Server ip: " + NetworkClient.serverIp);
GUILayout.Label("Time since last message: " + sb.AppendLine("Time since last message: " +
(Time.time - NetworkClient.connection.lastMessageTime)); (Time.time - NetworkClient.connection.lastMessageTime));
} }
GUILayout.Label($"Num spawned network objects: {NetManager.NumSpawnedNetworkObjects}"); sb.AppendLine($"Num spawned network objects: {NetManager.NumSpawnedNetworkObjects}");
GUILayout.Label(sb.ToString());
}
private static void AddTimeSpan(System.Text.StringBuilder sb, string text, double seconds)
{
sb.AppendLine($"{text}: {TimeSpan.FromSeconds(seconds)}");
} }
} }
} }