using System.Collections; using System.Collections.Generic; using UnityEngine; namespace Beyond { public class FPSCounter : MonoBehaviour { private float m_FPSDisplay; private float m_averageFPSDisplay; private float m_minFPSDisplay; private float m_maxFPSDisplay; private float m_fps; private float m_minFPS = Mathf.Infinity; private float m_maxFPS = 0f; private int m_framesPassed = 0; private float m_fpsTotal = 0f; private int startDelay = 20; [SerializeField] private int m_y = 40; [SerializeField] private int m_Padding = -30; [SerializeField, Range(0f, 1f)] private float screenOffset = 0.85f; private int m_x = 5; private int m_width = 300; private int m_height = 25; // Update is called once per frame void Update() { m_x = (int)(Screen.width * screenOffset); m_fps = 1 / Time.unscaledDeltaTime; m_FPSDisplay = (int)m_fps; m_fpsTotal += m_fps; m_framesPassed++; m_averageFPSDisplay = (int)(m_fpsTotal / m_framesPassed); if (m_fps > m_maxFPS && m_framesPassed > startDelay) { m_maxFPS = m_fps; m_maxFPSDisplay = (int)m_maxFPS; } if (m_fps < m_minFPS && m_framesPassed > startDelay) { m_minFPS = m_fps; m_minFPSDisplay = (int)m_minFPS; } } void OnGUI() { GUIStyle style = new GUIStyle(); style.fontSize = 30; style.normal.textColor = Color.white; GUI.Label(new Rect(m_x, m_y + m_Padding, m_width, m_height), "FPS : " + m_FPSDisplay, style); GUI.Label(new Rect(m_x, m_y + m_y + m_Padding, m_width, m_height), "avg FPS: " + m_averageFPSDisplay, style); GUI.Label(new Rect(m_x, m_y + m_y + m_y + m_Padding, m_width, m_height), "min FPS: " + m_minFPSDisplay, style); GUI.Label(new Rect(m_x, m_y + m_y + m_y + m_y + m_Padding, m_width, m_height), "max FPS: " + m_maxFPSDisplay, style); } } }