NLDClient-yudde/ProjectNLD/Assets/Code/Scripts/GameWrapper/InformationShower.cs

32 lines
815 B
C#
Raw Normal View History

2023-11-23 16:32:56 +08:00
using UnityEngine;
public class InformationShower : MonoBehaviour
{
2024-08-26 16:46:28 +08:00
#if DEVELOPMENT_BUILD || DEBUG
2023-11-23 16:32:56 +08:00
[SerializeField]
private float _fpsRefreshTime = 0.1f;
private float _tickTime;
private int _tickFrameCount;
private int _frameRate;
private GUIStyle _labelStyle;
void Update()
{
_tickTime += Time.deltaTime;
_tickFrameCount++;
if (_tickTime >= _fpsRefreshTime)
{
2024-08-26 16:46:28 +08:00
_frameRate = Mathf.RoundToInt(1f / (_tickTime / _tickFrameCount));
_tickTime = 0f;
2023-11-23 16:32:56 +08:00
_tickFrameCount = 0;
}
}
private void OnGUI()
{
2024-08-26 16:46:28 +08:00
_labelStyle ??= GUI.skin.label;
2023-11-23 16:32:56 +08:00
_labelStyle.fontSize = 60;
2024-08-26 16:46:28 +08:00
GUI.Label(new Rect(Screen.width / 2f - 100f, 20f, 300f, 200f), $"FPS:{_frameRate}", _labelStyle);
2023-11-23 16:32:56 +08:00
}
2024-08-26 16:46:28 +08:00
#endif
}