FPS.cs 863 B

12345678910111213141516171819202122232425262728293031323334353637
  1. using UnityEngine;
  2. namespace Mirror.Examples.Cubes
  3. {
  4. public class FPS : MonoBehaviour
  5. {
  6. // fps accessible to the outside
  7. public int framesPerSecond { get; private set; }
  8. // configuration
  9. public bool showGUI = true;
  10. public bool showLog = false;
  11. // helpers
  12. int count;
  13. double startTime;
  14. protected void Update()
  15. {
  16. ++count;
  17. if (Time.time >= startTime + 1)
  18. {
  19. framesPerSecond = count;
  20. startTime = Time.time;
  21. count = 0;
  22. if (showLog) Debug.Log($"FPS: {framesPerSecond}");
  23. }
  24. }
  25. protected void OnGUI()
  26. {
  27. if (!showGUI) return;
  28. GUI.Label(new Rect(Screen.width - 70, 0, 70, 25), $"FPS: {framesPerSecond}");
  29. }
  30. }
  31. }