using UnityEngine; using UnityEngine.UI; namespace Crosstales.UI.Util { public class FPSDisplay : MonoBehaviour { public Text FPS; private float deltaTime; private float elapsedTime; private float msec; private float fps; private string text; public void Update() { deltaTime += (Time.deltaTime - deltaTime) * 0.1f; elapsedTime += Time.deltaTime; if (elapsedTime > 1f) { if (Time.frameCount % 3 == 0 && FPS != null) { msec = deltaTime * 1000f; fps = 1f / deltaTime; text = string.Format("FPS: {0:0.} ({1:0.0} ms)", fps, msec); if (fps < 15f) { FPS.text = "" + text + ""; } else if (fps < 29f) { FPS.text = "" + text + ""; } else { FPS.text = "" + text + ""; } } } else { FPS.text = "...calculating FPS..."; } } } }