57 lines
1.9 KiB
C#
57 lines
1.9 KiB
C#
using System.Text;
|
|
using RebootKit.Engine.Main;
|
|
using RebootKit.Engine.UI;
|
|
using Unity.Netcode;
|
|
using Unity.Netcode.Transports.UTP;
|
|
using UnityEngine;
|
|
using UnityEngine.UIElements;
|
|
|
|
namespace RebootKit.Engine.Services.Development {
|
|
public class DebugOverlayView : UIDocumentView {
|
|
const string k_DebugLabelClassName = "rr__debug-label";
|
|
|
|
VisualElement m_RootElement;
|
|
|
|
Label m_FPSLabel;
|
|
Label m_NetworkStatsLabel;
|
|
|
|
void Update() {
|
|
if (m_RootElement == null) {
|
|
return;
|
|
}
|
|
|
|
Resolution resolution = Screen.currentResolution;
|
|
m_FPSLabel.text = $"fps: {Mathf.RoundToInt(1f / Time.deltaTime)} | dt: {Time.deltaTime:F4}ms | runtime: {Time.time:F4}s | resolution: {resolution.width}x{resolution.height}@{resolution.refreshRateRatio}Hz";
|
|
|
|
NetworkManager nm = NetworkManager.Singleton;
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
sb.Append("Network: ");
|
|
sb.Append($"IsServer: {nm.IsServer}");
|
|
sb.Append($" | IsClient: {nm.IsClient}");
|
|
sb.Append($" | IsHost: {nm.IsHost}");
|
|
|
|
m_NetworkStatsLabel.text = sb.ToString();
|
|
}
|
|
|
|
public override VisualElement Build() {
|
|
m_RootElement = new VisualElement();
|
|
|
|
CreateLabel($"Toggle Overlay [F3] | RebootKit | game: {Application.productName}, version: {Application.version}");
|
|
m_FPSLabel = CreateLabel($"FPS: {Application.targetFrameRate}");
|
|
|
|
m_NetworkStatsLabel = CreateLabel("Network Stats");
|
|
|
|
return m_RootElement;
|
|
}
|
|
|
|
Label CreateLabel(string text) {
|
|
Label label = (Label)LabelBuilder.New(text).Build();
|
|
label.AddToClassList(k_DebugLabelClassName);
|
|
|
|
m_RootElement.Add(label);
|
|
return label;
|
|
}
|
|
}
|
|
} |