Fps.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class Fps : MonoBehaviour {
  6. int FrameCount = 0;
  7. private float _framesPerSecond;
  8. private TextMesh textMesh;
  9. public static float lerp = 0.01f;
  10. public static float StartALLLogicAndRenderTime = 0;
  11. public static float tempALLLogicAndRenderTime = 0;
  12. public static float ALLLogicAndRenderTime = 0;
  13. public static float tempALLLogicTime = 0;
  14. public static float ALLLogicTime = 0;
  15. public static float tempLeftRenderTime = 0;
  16. public static float LeftRenderTime = 0;
  17. public static float tempRightRenderTime = 0;
  18. public static float RightRenderTime = 0;
  19. public static float tempALLWaitLockTime = 0;
  20. public static float ALLWaitLockTime = 0;
  21. public static float tempControllerLogic1Time = 0;
  22. public static float ControllerLogic1Time = 0;
  23. public static float tempControllerLogic2Time = 0;
  24. public static float ControllerLogic2Time = 0;
  25. public static float tempRayCasterTime = 0;
  26. public static float ALLRayCasterTime = 0;
  27. // Use this for initialization
  28. void Start () {
  29. textMesh = GetComponent<TextMesh>();
  30. if(textMesh) {
  31. StartCoroutine(CalculateFramesPerSecond());
  32. }
  33. }
  34. float frameTime = 0;
  35. float delat = 0;
  36. // Update is called once per frame
  37. void FixedUpdate() {
  38. FrameCount++;
  39. delat = Mathf.Lerp(delat, (Time.realtimeSinceStartup - frameTime) * 1000, lerp);
  40. frameTime = Time.realtimeSinceStartup;
  41. textMesh.text = string.Format("{0:F2}", _framesPerSecond);
  42. /*
  43. textMesh.text += "\n" + string.Format("{0:F1}" + " ms", delat);
  44. textMesh.text += "\n Logic_Render:" + string.Format("{0:F3}" + " ms", ALLLogicAndRenderTime);
  45. textMesh.text += "\n Logic:" + string.Format("{0:F3}" + " ms", ALLLogicTime);
  46. textMesh.text += "\n LeftCameraRender:" + string.Format("{0:F3}" + " ms", LeftRenderTime);
  47. textMesh.text += "\n RightCameraRender:" + string.Format("{0:F3}" + " ms", RightRenderTime);
  48. textMesh.text += "\n WaitATW:" + string.Format("{0:F3}" + " ms", ALLWaitLockTime);
  49. textMesh.text += "\n ControllerUpdate:" + string.Format("{0:F3}" + " ms", ControllerLogic1Time);
  50. textMesh.text += "\n ControllerLateUpdate:" + string.Format("{0:F3}" + " ms", ControllerLogic2Time);
  51. textMesh.text += "\n ALLRayCaster:" + string.Format("{0:F3}" + " ms", ALLRayCasterTime);
  52. if (API_GSXR_Module_InputSystem_KS.GSXR_KSLeft) {
  53. textMesh.text += "\n KSLeft:" + string.Format("{0:F3}", API_GSXR_Module_InputSystem_KS.GSXR_KSLeft.inputDeviceKSPartUI.modelBase.transform.position);
  54. }
  55. if (API_GSXR_Module_InputSystem_KS.GSXR_KSRight) {
  56. textMesh.text += "\n KSRight:" + string.Format("{0:F3}", API_GSXR_Module_InputSystem_KS.GSXR_KSRight.inputDeviceKSPartUI.modelBase.transform.position);
  57. }
  58. if (API_GSXR_Slam.GSXR_Get_Head()) {
  59. textMesh.text += "\n Head Rotation:" + string.Format("{0:F3}", API_GSXR_Slam.GSXR_Get_Head().localEulerAngles);
  60. textMesh.text += "\n Head Position:" + string.Format("{0:F3}", API_GSXR_Slam.GSXR_Get_Head().localPosition);
  61. }*/
  62. }
  63. private IEnumerator CalculateFramesPerSecond() {
  64. int lastFrameCount = 0;
  65. while (true) {
  66. yield return new WaitForSecondsRealtime(1f);
  67. var elapsedFrames = FrameCount - lastFrameCount;
  68. _framesPerSecond = elapsedFrames / 1f;
  69. lastFrameCount = FrameCount;
  70. }
  71. }
  72. }