[+] FrameRate lock + display

This commit is contained in:
Clansty
2024-10-02 00:52:37 +08:00
parent 9ead7a413e
commit c15dcf6b98
8 changed files with 233 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
using AquaMai.Helpers;
using HarmonyLib;
using Main;
using UnityEngine;
namespace AquaMai.Utils;
public class FrameRateDisplay
{
[HarmonyPatch(typeof(GameMainObject), "Awake")]
[HarmonyPostfix]
public static void ShowUi(GameMainObject __instance)
{
__instance.gameObject.AddComponent<Ui>();
}
private class Ui : MonoBehaviour
{
private static float sampleTime = 1f;
private static int frame;
private static float time;
private static float fps;
public void OnGUI()
{
var labelStyle = GUI.skin.GetStyle("label");
labelStyle.fontSize = GuiSizes.FontSize;
labelStyle.alignment = TextAnchor.MiddleCenter;
const float x = 10f;
const float y = 10f;
var width = GuiSizes.FontSize * 7f;
var height = GuiSizes.LabelHeight * 1.5f;
frame += 1;
time += Time.deltaTime;
if (time >= sampleTime)
{
fps = frame / time;
frame = 0;
time = 0;
}
GUI.Box(new Rect(x, y, width, height), "");
GUI.Label(new Rect(x, y, width, height), $"{fps:0.0} FPS");
}
}
}