32 lines
763 B
C#
32 lines
763 B
C#
using QFSW.QC;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
|
|
public class PerformanceMonitor : MonoBehaviour
|
|
{
|
|
public TextMeshProUGUI performanceText;
|
|
|
|
private float _deltaTime;
|
|
|
|
private bool _isEnabled;
|
|
|
|
[Command("EnableFPSCounter", Platform.AllPlatforms, MonoTargetType.Single)]
|
|
private void EnableFPSCounter(bool set)
|
|
{
|
|
_isEnabled = set;
|
|
performanceText.gameObject.SetActive(set);
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (_isEnabled && !(performanceText == null))
|
|
{
|
|
_deltaTime += (Time.unscaledDeltaTime - _deltaTime) * 0.1f;
|
|
float num = 1f / _deltaTime;
|
|
float num2 = Time.deltaTime * 1000f;
|
|
float num3 = _deltaTime * 1000f;
|
|
performanceText.text = $"FPS: {num:F1}\n" + $"GPU ms (approx): {num2:F2} ms\n" + $"CPU ms (approx): {num3:F2} ms\n";
|
|
}
|
|
}
|
|
}
|