NLDClient-yudde/ProjectNLD/Assets/Code/Scripts/Gameplay/Utils/InformationShower.cs

38 lines
913 B
C#

using UnityEngine;
public class InformationShower : MonoBehaviour
{
[SerializeField]
private float _fpsRefreshTime = 0.1f;
private float _tickTime;
private int _tickFrameCount;
private int _frameRate;
private GUIStyle _labelStyle;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
_tickTime += Time.deltaTime;
_tickFrameCount++;
if (_tickTime >= _fpsRefreshTime)
{
_frameRate = Mathf.RoundToInt(1f/(_tickTime / _tickFrameCount));
_tickTime = 0;
_tickFrameCount = 0;
}
}
private void OnGUI()
{
_labelStyle = _labelStyle ?? GUI.skin.label;
_labelStyle.fontSize = 60;
GUI.Label(new Rect(Screen.width/2f - 100f,20f,300f,200f), $"FPS:{_frameRate}",_labelStyle);
}
}