12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- 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;
-
- void Start () {
-
- textMesh = GetComponent<TextMesh>();
- if(textMesh) {
- StartCoroutine(CalculateFramesPerSecond());
- }
- }
- float frameTime = 0;
- float delat = 0;
-
- void Update() {
- FrameCount++;
- delat = Mathf.Lerp(delat, (Time.realtimeSinceStartup - frameTime) * 1000, lerp);
- frameTime = Time.realtimeSinceStartup;
- textMesh.text = string.Format("{0:F2}", _framesPerSecond);
-
- }
- private IEnumerator CalculateFramesPerSecond() {
- int lastFrameCount = 0;
- while (true) {
- yield return new WaitForSecondsRealtime(1f);
-
- var elapsedFrames = FrameCount - lastFrameCount;
- _framesPerSecond = elapsedFrames / 1f;
-
- lastFrameCount = FrameCount;
- }
- }
- }
|