|
- using System;
- using UnityEngine;
-
- namespace SUISS.Core
- {
- public class FPSCounter : MonoBehaviour
- {
- public static void Create()
- {
- }
-
- protected virtual void Start()
- {
- this._style = new GUIStyle(GUIStyle.none);
- this._style.fontSize = 20;
- this._style.normal.textColor = Color.white;
- base.InvokeRepeating("CalculateFramerate", 0f, 0.05f);
- }
-
- protected virtual void OnGUI()
- {
- GUI.backgroundColor = Color.blue;
- GUI.BeginGroup(Rect.MinMaxRect(10f, 10f, 100f, 40f));
- GUI.Box(Rect.MinMaxRect(0f, 0f, 90f, 30f), string.Empty);
- GUI.Label(Rect.MinMaxRect(10f, 0f, 80f, 20f), string.Format("{0:0.000}", this._fps), this._style);
- GUI.EndGroup();
- }
-
- protected virtual void Update()
- {
- this._deltaTime += Time.unscaledDeltaTime;
- this._frameCount++;
- }
-
- private void CalculateFramerate()
- {
- if (this._frameCount == 0 || this._deltaTime == 0f)
- {
- return;
- }
- this._fps = (float)this._frameCount / this._deltaTime;
- this._frameCount = 0;
- this._deltaTime = 0f;
- }
-
- private static FPSCounter _instance;
-
- protected float _deltaTime;
-
- protected int _frameCount;
-
- protected float _fps;
-
- protected GUIStyle _style;
- }
- }
|