string GetPlayerStatistics(Record rec) { uLink.NetworkStatistics netStats = rec.networkPlayer.statistics; string res = string.Format(StatisticsFormat, rec.ppi.Name, rec.averagePing, netStats.bytesReceived, netStats.packetsReceived, netStats.bytesSent, netStats.packetsSent, netStats.messagesResent, netStats.messagesUnsent ); return(res); }
private void StatisticsGUI() { uLink.NetworkPlayer[] connections = uLink.Network.connections; uLink.NetworkView[] networkViews = uLink.Network.networkViews; GUILayout.BeginVertical("Box"); GUILayout.BeginHorizontal(); GUILayout.Label("Frame Rate:", GUILayout.Width(COLUMN_WIDTH)); if (Application.isPlaying) { GUILayout.Label(Mathf.RoundToInt(1.0f / Time.smoothDeltaTime).ToString(CultureInfo.InvariantCulture) + " FPS"); } else { GUILayout.Label("N/A"); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Status:", GUILayout.Width(COLUMN_WIDTH)); GUILayout.Label(uLink.NetworkUtility.GetStatusString(uLink.Network.peerType, uLink.Network.status)); GUILayout.EndHorizontal(); var listenEndPoint = uLink.Network.listenEndPoint; if (!listenEndPoint.isUnassigned) { GUILayout.BeginHorizontal(); GUILayout.Label("Listen EndPoint:", GUILayout.Width(COLUMN_WIDTH)); GUILayout.Label(listenEndPoint.ToRawString()); GUILayout.EndHorizontal(); } GUILayout.BeginHorizontal(); GUILayout.Label("Last Error:", GUILayout.Width(COLUMN_WIDTH)); GUILayout.Label(uLink.NetworkUtility.GetErrorString(uLink.Network.lastError)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Network Time:", GUILayout.Width(COLUMN_WIDTH)); GUILayout.Label(uLink.Network.time.ToString(CultureInfo.InvariantCulture) + " s"); GUILayout.EndHorizontal(); if (showDetails) { GUILayout.BeginHorizontal(); GUILayout.Label("Server Time Offset:", GUILayout.Width(COLUMN_WIDTH)); GUILayout.Label((uLink.Network.config.serverTimeOffset).ToString(CultureInfo.InvariantCulture) + " s"); GUILayout.EndHorizontal(); } GUILayout.BeginHorizontal(); GUILayout.Label("Network Objects:", GUILayout.Width(COLUMN_WIDTH)); GUILayout.Label(networkViews.Length.ToString(CultureInfo.InvariantCulture)); GUILayout.EndHorizontal(); if (uLink.Network.isServer) { GUILayout.BeginHorizontal(); GUILayout.Label("Connections:", GUILayout.Width(COLUMN_WIDTH)); GUILayout.Label(connections.Length.ToString(CultureInfo.InvariantCulture)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Name in Master Server:", GUILayout.Width(COLUMN_WIDTH)); GUILayout.Label(uLink.MasterServer.isRegistered ? uLink.MasterServer.gameName : "Not Registered"); GUILayout.EndHorizontal(); } GUILayout.EndVertical(); foreach (var player in connections) { uLink.NetworkStatistics stats = player.statistics; if (stats == null) { continue; } GUILayout.BeginVertical("Box"); GUILayout.BeginHorizontal(); GUILayout.Label("Player:", GUILayout.Width(COLUMN_WIDTH)); GUILayout.Label(player.ToString()); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Ping (average):", GUILayout.Width(COLUMN_WIDTH)); GUILayout.Label(player.lastPing + " (" + player.averagePing + ") ms"); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Sent:", GUILayout.Width(COLUMN_WIDTH)); GUILayout.Label((int)stats.bytesSentPerSecond + " B/s"); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Received:", GUILayout.Width(COLUMN_WIDTH)); GUILayout.Label((int)stats.bytesReceivedPerSecond + " B/s"); GUILayout.EndHorizontal(); if (showDetails) { GUILayout.BeginHorizontal(); GUILayout.Label("Packets sent:", GUILayout.Width(COLUMN_WIDTH)); GUILayout.Label(stats.packetsSent.ToString(CultureInfo.InvariantCulture)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Packets received:", GUILayout.Width(COLUMN_WIDTH)); GUILayout.Label(stats.packetsReceived.ToString(CultureInfo.InvariantCulture)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Messages sent:", GUILayout.Width(COLUMN_WIDTH)); GUILayout.Label(stats.messagesSent.ToString(CultureInfo.InvariantCulture)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Messages received:", GUILayout.Width(COLUMN_WIDTH)); GUILayout.Label(stats.messagesReceived.ToString(CultureInfo.InvariantCulture)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Messages resent:", GUILayout.Width(COLUMN_WIDTH)); GUILayout.Label(stats.messagesResent.ToString(CultureInfo.InvariantCulture)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Messages unsent:", GUILayout.Width(COLUMN_WIDTH)); GUILayout.Label(stats.messagesUnsent.ToString(CultureInfo.InvariantCulture)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Messages stored:", GUILayout.Width(COLUMN_WIDTH)); GUILayout.Label(stats.messagesStored.ToString(CultureInfo.InvariantCulture)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Messages withheld:", GUILayout.Width(COLUMN_WIDTH)); GUILayout.Label(stats.messagesWithheld.ToString(CultureInfo.InvariantCulture)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Msg duplicates rejected:", GUILayout.Width(COLUMN_WIDTH)); GUILayout.Label(stats.messageDuplicatesRejected.ToString(CultureInfo.InvariantCulture)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Msg sequences rejected:", GUILayout.Width(COLUMN_WIDTH)); GUILayout.Label(stats.messageSequencesRejected.ToString(CultureInfo.InvariantCulture)); GUILayout.EndHorizontal(); } GUILayout.BeginHorizontal(); GUILayout.Label("Encryption:", GUILayout.Width(COLUMN_WIDTH)); GUILayout.Label(player.securityStatus.ToString()); GUILayout.EndHorizontal(); GUILayout.EndVertical(); } }
public static void DrawGUI(Position position, bool showDetails) { uLink.NetworkPlayer[] connections = uLink.Network.connections; GUILayout.BeginArea(new Rect(0, 0, Screen.width, Screen.height)); GUILayout.BeginHorizontal(); if (position == Position.TopLeft || position == Position.BottomLeft) { GUILayout.Space(WINDOW_MARGIN_X); } else { GUILayout.FlexibleSpace(); } GUILayout.BeginVertical(); if (position == Position.TopLeft || position == Position.TopRight) { GUILayout.Space(WINDOW_MARGIN_Y); } else { GUILayout.FlexibleSpace(); } GUILayout.BeginVertical(GUILayout.Width(WINDOW_WDITH)); GUILayout.BeginVertical(GUI.skin.box); GUILayout.BeginHorizontal(); GUILayout.Label("Frame Rate:", GUILayout.Width(COLUMN_WIDTH)); GUILayout.Label(Mathf.RoundToInt(1.0f / Time.smoothDeltaTime).ToString(CultureInfo.InvariantCulture) + " FPS"); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Status:", GUILayout.Width(COLUMN_WIDTH)); GUILayout.Label(uLink.NetworkUtility.GetStatusString(uLink.Network.peerType, uLink.Network.status)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Last Error:", GUILayout.Width(COLUMN_WIDTH)); GUILayout.Label(uLink.NetworkUtility.GetErrorString(uLink.Network.lastError)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Network Time:", GUILayout.Width(COLUMN_WIDTH)); GUILayout.Label(uLink.Network.time.ToString(CultureInfo.InvariantCulture) + " s"); GUILayout.EndHorizontal(); if (showDetails) { GUILayout.BeginHorizontal(); GUILayout.Label("Server Time Offset:", GUILayout.Width(COLUMN_WIDTH)); GUILayout.Label((uLink.Network.config.serverTimeOffsetInMillis * 0.001).ToString(CultureInfo.InvariantCulture) + " s"); GUILayout.EndHorizontal(); } GUILayout.BeginHorizontal(); GUILayout.Label("Network Objects:", GUILayout.Width(COLUMN_WIDTH)); GUILayout.Label(uLink.Network.networkViewCount.ToString(CultureInfo.InvariantCulture)); GUILayout.EndHorizontal(); if (uLink.Network.isServer) { GUILayout.BeginHorizontal(); GUILayout.Label("Connections:", GUILayout.Width(COLUMN_WIDTH)); GUILayout.Label(connections.Length.ToString(CultureInfo.InvariantCulture)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Name in Master Server:", GUILayout.Width(COLUMN_WIDTH)); GUILayout.Label(uLink.MasterServer.isRegistered ? uLink.MasterServer.gameName : "Not Registered"); GUILayout.EndHorizontal(); } GUILayout.EndVertical(); foreach (var player in connections) { uLink.NetworkStatistics stats = player.statistics; if (stats == null) { continue; } GUILayout.BeginVertical("Box"); GUILayout.BeginHorizontal(); GUILayout.Label("Connection:", GUILayout.Width(COLUMN_WIDTH)); GUILayout.Label(player.ToString()); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Ping (average):", GUILayout.Width(COLUMN_WIDTH)); GUILayout.Label(player.lastPing + " (" + player.averagePing + ") ms"); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Sent:", GUILayout.Width(COLUMN_WIDTH)); GUILayout.Label((int)Math.Round(stats.bytesSentPerSecond) + " B/s"); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Receive:", GUILayout.Width(COLUMN_WIDTH)); GUILayout.Label((int)Math.Round(stats.bytesReceivedPerSecond) + " B/s"); GUILayout.EndHorizontal(); if (showDetails) { GUILayout.BeginHorizontal(); GUILayout.Label("Packets sent:", GUILayout.Width(COLUMN_WIDTH)); GUILayout.Label(stats.packetsSent.ToString(CultureInfo.InvariantCulture)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Packets received:", GUILayout.Width(COLUMN_WIDTH)); GUILayout.Label(stats.packetsReceived.ToString(CultureInfo.InvariantCulture)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Messages sent:", GUILayout.Width(COLUMN_WIDTH)); GUILayout.Label(stats.messagesSent.ToString(CultureInfo.InvariantCulture)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Messages received:", GUILayout.Width(COLUMN_WIDTH)); GUILayout.Label(stats.messagesReceived.ToString(CultureInfo.InvariantCulture)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Messages resent:", GUILayout.Width(COLUMN_WIDTH)); GUILayout.Label(stats.messagesResent.ToString(CultureInfo.InvariantCulture)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Messages unsent:", GUILayout.Width(COLUMN_WIDTH)); GUILayout.Label(stats.messagesUnsent.ToString(CultureInfo.InvariantCulture)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Messages stored:", GUILayout.Width(COLUMN_WIDTH)); GUILayout.Label(stats.messagesStored.ToString(CultureInfo.InvariantCulture)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Messages withheld:", GUILayout.Width(COLUMN_WIDTH)); GUILayout.Label(stats.messagesWithheld.ToString(CultureInfo.InvariantCulture)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Msg duplicates rejected:", GUILayout.Width(COLUMN_WIDTH)); GUILayout.Label(stats.messageDuplicatesRejected.ToString(CultureInfo.InvariantCulture)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Msg sequences rejected:", GUILayout.Width(COLUMN_WIDTH)); GUILayout.Label(stats.messageSequencesRejected.ToString(CultureInfo.InvariantCulture)); GUILayout.EndHorizontal(); } GUILayout.BeginHorizontal(); GUILayout.Label("Encryption:", GUILayout.Width(COLUMN_WIDTH)); GUILayout.Label(player.hasSecurity ? "On" : "Off"); GUILayout.EndHorizontal(); GUILayout.EndVertical(); } GUILayout.EndVertical(); if (position != Position.TopLeft && position != Position.TopRight) { GUILayout.Space(WINDOW_MARGIN_Y); } else { GUILayout.FlexibleSpace(); } GUILayout.EndVertical(); if (position != Position.TopLeft && position != Position.BottomLeft) { GUILayout.Space(WINDOW_MARGIN_X); } else { GUILayout.FlexibleSpace(); } GUILayout.EndHorizontal(); GUILayout.EndArea(); }
public static void DrawGUI(bool showFrameRate) { uLink.NetworkPlayer[] connections = uLink.Network.connections; uLink.NetworkView[] networkViews = uLink.Network.networkViews; GUILayout.BeginArea(new Rect(0, 0, Screen.width, Screen.height)); GUILayout.BeginHorizontal(); GUILayout.Space(10); GUILayout.BeginVertical(); GUILayout.Space(10); GUILayout.BeginVertical(GUILayout.Width(300)); GUILayout.BeginVertical("Box"); if (showFrameRate) { GUILayout.BeginHorizontal(); GUILayout.Label("Frame Rate:", GUILayout.Width(150)); GUILayout.Label(Mathf.RoundToInt(1.0f / Time.smoothDeltaTime) + " FPS"); GUILayout.EndHorizontal(); } GUILayout.BeginHorizontal(); GUILayout.Label("Status:", GUILayout.Width(150)); GUILayout.Label(uLink.NetworkUtility.GetStatusString(uLink.Network.peerType, uLink.Network.status)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Last Error:", GUILayout.Width(150)); GUILayout.Label(uLink.NetworkUtility.GetErrorString(uLink.Network.lastError)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Network Time:", GUILayout.Width(150)); GUILayout.Label(uLink.Network.time + " s"); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Network Objects:", GUILayout.Width(150)); GUILayout.Label(networkViews.Length.ToString()); GUILayout.EndHorizontal(); if (uLink.Network.isServer) { GUILayout.BeginHorizontal(); GUILayout.Label("Connections:", GUILayout.Width(150)); GUILayout.Label(connections.Length.ToString()); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Name in Master Server:", GUILayout.Width(150)); GUILayout.Label(uLink.MasterServer.isRegisterd ? uLink.MasterServer.gameName : "Not Registered"); GUILayout.EndHorizontal(); } GUILayout.EndVertical(); foreach (uLink.NetworkPlayer player in connections) { uLink.NetworkStatistics stats = player.statistics; if (stats == null) { continue; } GUILayout.BeginVertical("Box"); GUILayout.BeginHorizontal(); GUILayout.Label("Player:", GUILayout.Width(150)); GUILayout.Label(player.ToString()); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Ping (average):", GUILayout.Width(150)); GUILayout.Label(player.lastPing + " (" + player.averagePing + ") ms"); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Sent:", GUILayout.Width(150)); GUILayout.Label((int)Math.Round(stats.bytesSentPerSecond) + " B/s"); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Receive:", GUILayout.Width(150)); GUILayout.Label((int)Math.Round(stats.bytesReceivedPerSecond) + " B/s"); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Encryption:", GUILayout.Width(150)); GUILayout.Label(player.hasSecurity ? "On" : "Off"); GUILayout.EndHorizontal(); GUILayout.EndVertical(); } GUILayout.EndVertical(); GUILayout.FlexibleSpace(); GUILayout.EndVertical(); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.EndArea(); }