Files
Sinmai-Assist/Common/ShowFPS.cs
2025-10-13 18:18:47 +08:00

28 lines
782 B
C#

using UnityEngine;
namespace SinmaiAssist.Common;
public class ShowFPS
{
private static string fpsText = "FPS: ";
private static float deltaTime = 0.0f;
public static void OnGUI()
{
Update();
GUIStyle style = new GUIStyle();
style.fontSize = 24;
style.normal.textColor = Color.black;
style.alignment = TextAnchor.UpperLeft;
UnityEngine.GUI.Label(new Rect(10 + 2, 10 + 2, 500, 30), fpsText, style);
style.normal.textColor = Color.white;
UnityEngine.GUI.Label(new Rect(10, 10, 500, 30), fpsText, style);
}
private static void Update()
{
deltaTime += (Time.deltaTime - deltaTime) * 0.1f;
float fps = 1.0f / deltaTime;
fpsText = $"FPS: {Mathf.Ceil(fps)}";
}
}