您不能選擇超過 %s 個話題 話題必須以字母或數字為開頭,可包含連接號 ('-') 且最長為 35 個字
 
 
 

57 行
1.2 KiB

  1. using System;
  2. using UnityEngine;
  3. namespace SUISS.Core
  4. {
  5. public class FPSCounter : MonoBehaviour
  6. {
  7. public static void Create()
  8. {
  9. }
  10. protected virtual void Start()
  11. {
  12. this._style = new GUIStyle(GUIStyle.none);
  13. this._style.fontSize = 20;
  14. this._style.normal.textColor = Color.white;
  15. base.InvokeRepeating("CalculateFramerate", 0f, 0.05f);
  16. }
  17. protected virtual void OnGUI()
  18. {
  19. GUI.backgroundColor = Color.blue;
  20. GUI.BeginGroup(Rect.MinMaxRect(10f, 10f, 100f, 40f));
  21. GUI.Box(Rect.MinMaxRect(0f, 0f, 90f, 30f), string.Empty);
  22. GUI.Label(Rect.MinMaxRect(10f, 0f, 80f, 20f), string.Format("{0:0.000}", this._fps), this._style);
  23. GUI.EndGroup();
  24. }
  25. protected virtual void Update()
  26. {
  27. this._deltaTime += Time.unscaledDeltaTime;
  28. this._frameCount++;
  29. }
  30. private void CalculateFramerate()
  31. {
  32. if (this._frameCount == 0 || this._deltaTime == 0f)
  33. {
  34. return;
  35. }
  36. this._fps = (float)this._frameCount / this._deltaTime;
  37. this._frameCount = 0;
  38. this._deltaTime = 0f;
  39. }
  40. private static FPSCounter _instance;
  41. protected float _deltaTime;
  42. protected int _frameCount;
  43. protected float _fps;
  44. protected GUIStyle _style;
  45. }
  46. }