From 6ce8b9e22fc13be34b442c7b6af48b42cd44275a Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Wed, 13 Mar 2024 11:00:58 +0800 Subject: +init --- FPSmeter.cs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 FPSmeter.cs (limited to 'FPSmeter.cs') diff --git a/FPSmeter.cs b/FPSmeter.cs new file mode 100644 index 0000000..f762fe7 --- /dev/null +++ b/FPSmeter.cs @@ -0,0 +1,40 @@ +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; + } + } +} -- cgit v1.1-26-g67d0