Cyber/Assets/Scripts/Controls/NetworkDebugControl.cs

40 lines
1.1 KiB
C#
Raw Permalink Normal View History

2017-05-16 23:57:03 +02:00
using Cyber.Networking;
using Cyber.Networking.Clientside;
2017-05-16 23:25:29 +02:00
using UnityEngine;
using UnityEngine.UI;
public class NetworkDebugControl : MonoBehaviour {
public Text PacketLossNumberText;
public Text PingNumberText;
public Text PacketsReceivedNumberText;
public RectTransform ActualPanel;
private bool visible = false;
2017-05-16 23:57:03 +02:00
private double LastPingChecked = 0.5;
2017-05-16 23:25:29 +02:00
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetButtonDown("ToggleNetworkDebug")) {
visible = !visible && Client.IsRunning();
ActualPanel.gameObject.SetActive(visible);
}
if (visible) {
2017-05-16 23:57:03 +02:00
LastPingChecked += Time.deltaTime;
if (LastPingChecked > 0.5) {
PingNumberText.text = ((int) (Client.GetSyncHandler().GetPing())) + "ms";
LastPingChecked -= 0.5;
}
2017-05-16 23:25:29 +02:00
PacketLossNumberText.text = ((int) (Client.GetSyncHandler().GetPacketLoss() * 10000) * 1f / 100) + "%";
PacketsReceivedNumberText.text = Client.GetSyncHandler().GetSyncPacketsReceived() + "";
}
}
}