using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class Fps : MonoBehaviour { int FrameCount = 0; private float _framesPerSecond; private TextMesh textMesh; public static float lerp = 0.01f; public static float StartALLLogicAndRenderTime = 0; public static float tempALLLogicAndRenderTime = 0; public static float ALLLogicAndRenderTime = 0; public static float tempALLLogicTime = 0; public static float ALLLogicTime = 0; public static float tempLeftRenderTime = 0; public static float LeftRenderTime = 0; public static float tempRightRenderTime = 0; public static float RightRenderTime = 0; public static float tempALLWaitLockTime = 0; public static float ALLWaitLockTime = 0; public static float tempControllerLogic1Time = 0; public static float ControllerLogic1Time = 0; public static float tempControllerLogic2Time = 0; public static float ControllerLogic2Time = 0; public static float tempRayCasterTime = 0; public static float ALLRayCasterTime = 0; // Use this for initialization void Start () { // Application.targetFrameRate = 70; textMesh = GetComponent(); if(textMesh) { StartCoroutine(CalculateFramesPerSecond()); } } float frameTime = 0; float delat = 0; // Update is called once per frame void Update() { FrameCount++; delat = Mathf.Lerp(delat, (Time.realtimeSinceStartup - frameTime) * 1000, lerp); frameTime = Time.realtimeSinceStartup; textMesh.text = string.Format("{0:F2}", _framesPerSecond); /* textMesh.text += "\n" + string.Format("{0:F1}" + " ms", delat); textMesh.text += "\n Logic_Render:" + string.Format("{0:F3}" + " ms", ALLLogicAndRenderTime); textMesh.text += "\n Logic:" + string.Format("{0:F3}" + " ms", ALLLogicTime); textMesh.text += "\n LeftCameraRender:" + string.Format("{0:F3}" + " ms", LeftRenderTime); textMesh.text += "\n RightCameraRender:" + string.Format("{0:F3}" + " ms", RightRenderTime); textMesh.text += "\n WaitATW:" + string.Format("{0:F3}" + " ms", ALLWaitLockTime); textMesh.text += "\n ControllerUpdate:" + string.Format("{0:F3}" + " ms", ControllerLogic1Time); textMesh.text += "\n ControllerLateUpdate:" + string.Format("{0:F3}" + " ms", ControllerLogic2Time); textMesh.text += "\n ALLRayCaster:" + string.Format("{0:F3}" + " ms", ALLRayCasterTime); if (API_GSXR_Module_InputSystem_KS.GSXR_KSLeft) { textMesh.text += "\n KSLeft:" + string.Format("{0:F3}", API_GSXR_Module_InputSystem_KS.GSXR_KSLeft.inputDeviceKSPartUI.modelBase.transform.position); } if (API_GSXR_Module_InputSystem_KS.GSXR_KSRight) { textMesh.text += "\n KSRight:" + string.Format("{0:F3}", API_GSXR_Module_InputSystem_KS.GSXR_KSRight.inputDeviceKSPartUI.modelBase.transform.position); } if (API_GSXR_Slam.GSXR_Get_Head()) { textMesh.text += "\n Head Rotation:" + string.Format("{0:F3}", API_GSXR_Slam.GSXR_Get_Head().localEulerAngles); textMesh.text += "\n Head Position:" + string.Format("{0:F3}", API_GSXR_Slam.GSXR_Get_Head().localPosition); }*/ } private IEnumerator CalculateFramesPerSecond() { int lastFrameCount = 0; while (true) { yield return new WaitForSecondsRealtime(1f); var elapsedFrames = FrameCount - lastFrameCount; _framesPerSecond = elapsedFrames / 1f; lastFrameCount = FrameCount; } } }