41 lines
719 B
C#
41 lines
719 B
C#
using UnityEngine;
|
|
|
|
public class FPSmeter : MonoBehaviour
|
|
{
|
|
public float updateInterval = 0.5f;
|
|
|
|
private float lastInterval;
|
|
|
|
private int frames;
|
|
|
|
public static float fps;
|
|
|
|
public bool showFPS;
|
|
|
|
private void Start()
|
|
{
|
|
lastInterval = Time.realtimeSinceStartup;
|
|
frames = 0;
|
|
}
|
|
|
|
private void OnGUI()
|
|
{
|
|
if (showFPS)
|
|
{
|
|
GUI.Label(new Rect(10f, 10f, 100f, 20f), string.Empty + Mathf.Round(fps * 100f) / 100f);
|
|
}
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
frames++;
|
|
float realtimeSinceStartup = Time.realtimeSinceStartup;
|
|
if (realtimeSinceStartup > lastInterval + updateInterval)
|
|
{
|
|
fps = (float)frames / (realtimeSinceStartup - lastInterval);
|
|
frames = 0;
|
|
lastInterval = realtimeSinceStartup;
|
|
}
|
|
}
|
|
}
|