ProjectDDD/Assets/External/Free Slash VFX/Demo/Scripts/FPSCounter.cs

37 lines
912 B
C#
Raw Normal View History

2025-08-20 06:28:04 +00:00
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
namespace MaykerStudio.Demo
{
public class FPSCounter : MonoBehaviour
{
private TextMeshProUGUI textFPS;
// Add this to the class variables
[Range(1, 100)] public int smoothingFrames = 60;
private Queue<float> frameTimes = new Queue<float>();
void Start()
{
textFPS = GetComponent<TextMeshProUGUI>();
}
void Update()
{
frameTimes.Enqueue(Time.deltaTime);
if (frameTimes.Count > smoothingFrames)
{
frameTimes.Dequeue();
}
float averageDelta = 0;
foreach (float t in frameTimes) averageDelta += t;
averageDelta /= frameTimes.Count;
textFPS.text = $"FPS: {Mathf.RoundToInt(1f / averageDelta)}";
}
}
}