Update Setting

This commit is contained in:
2026-05-01 17:57:07 +07:00
parent bcb2c329c5
commit 9c784e77f8
26 changed files with 954 additions and 3233 deletions

View File

@@ -1,5 +1,6 @@
using UnityEngine;
using UnityEngine.UIElements;
using Fusion;
namespace Hallucinate.UI
{
@@ -35,18 +36,26 @@ namespace Hallucinate.UI
private void Awake()
{
_uiDocument = gameObject.AddComponent<UIDocument>();
// Use same panel settings as UIManager if possible, or default
_uiDocument.panelSettings = Resources.Load<PanelSettings>("UI/PerformancePanelSettings");
// Đặt thứ tự hiển thị cực cao để luôn nằm trên cùng
_uiDocument.sortingOrder = 999;
// Thử lấy PanelSettings từ UIManager để đồng bộ tỉ lệ scale
if (UIManager.Instance != null && UIManager.Instance.GetComponent<UIDocument>() != null)
{
_uiDocument.panelSettings = UIManager.Instance.GetComponent<UIDocument>().panelSettings;
}
_root = new VisualElement();
_root.style.position = Position.Absolute;
_root.style.bottom = 10;
_root.style.left = 10;
_root.style.bottom = 15;
_root.style.right = 15;
_root.pickingMode = PickingMode.Ignore;
_fpsLabel = new Label("0 FPS (0.0ms)");
_fpsLabel = new Label("0 FPS | 0.0ms | PING: 0ms");
_fpsLabel.pickingMode = PickingMode.Ignore;
_fpsLabel.style.color = Color.white;
_fpsLabel.style.fontSize = 14;
_fpsLabel.style.fontSize = 12;
_fpsLabel.style.unityFontStyleAndWeight = FontStyle.Bold;
// Shadow effect
_fpsLabel.style.textShadow = new TextShadow { offset = new Vector2(1, 1), blurRadius = 1, color = Color.black };
@@ -65,7 +74,19 @@ namespace Hallucinate.UI
float fps = 1.0f / _deltaTime;
float ms = _deltaTime * 1000.0f;
_fpsLabel.text = $"{Mathf.Ceil(fps)} FPS ({ms:F1}ms)";
int ping = 0;
if (BasicSpawner.Instance != null && BasicSpawner.Instance.Runner != null && BasicSpawner.Instance.Runner.IsRunning)
{
var runner = BasicSpawner.Instance.Runner;
if (runner.LocalPlayer != PlayerRef.None)
{
ping = (int)(runner.GetPlayerRtt(runner.LocalPlayer) * 1000);
}
}
var (_, deviceLatency) = MouseMetricsHelper.GetMetrics();
_fpsLabel.text = $"{Mathf.Ceil(fps)} FPS | {ms:F1}ms | LATENCY: {deviceLatency:F0}ms | PING: {ping}ms";
// Color coding based on performance
if (fps < 30) _fpsLabel.style.color = Color.red;