using UnityEngine; public class PerfHud : MonoBehaviour { public static bool Enabled = true; [Header("HUD")] public bool show = true; public int topN = 12; public bool sortByMax = false; public KeyCode toggleKey = KeyCode.F8; float _fps; void Awake() { DontDestroyOnLoad(gameObject); } void Update() { if (Input.GetKeyDown(toggleKey)) { Enabled = !Enabled; show = Enabled; } // FPS non lissé _fps = 1f / Time.unscaledDeltaTime; } void LateUpdate() { // Reset stats pour la frame suivante Perf.ResetFrame(); } void OnGUI() { if (!show) return; var rect = new Rect(10, 10, 520, 26); GUI.Label(rect, $"FPS: {_fps:F1} | Frame: {(Time.unscaledDeltaTime * 1000f):F2} ms | Toggle: {toggleKey}"); rect.y += 22; GUI.Label(rect, sortByMax ? "Top (MAX ms)" : "Top (TOTAL ms)"); rect.y += 18; var top = Perf.GetTop(topN, sortByMax); foreach (var s in top) { GUI.Label(new Rect(10, rect.y, 900, 20), $"{s.name,-35} calls:{s.calls,3} total:{s.msTotal,7:F2}ms avg:{s.MsAvg,6:F2}ms max:{s.msMax,6:F2}ms"); rect.y += 18; } } }