Rasagar/Assets/Viking Village/Standard Assets/Utility/FPSCounter.cs
2024-08-26 23:07:20 +03:00

39 lines
1.0 KiB
C#

using System;
using UnityEngine;
using UnityEngine.UI;
namespace UnityStandardAssets.Utility
{
[RequireComponent(typeof (Text))]
public class FPSCounter : MonoBehaviour
{
const float fpsMeasurePeriod = 0.5f;
private int m_FpsAccumulator = 0;
private float m_FpsNextPeriod = 0;
private int m_CurrentFps;
const string display = "{0} FPS";
private Text m_GuiText;
private void Start()
{
m_FpsNextPeriod = Time.realtimeSinceStartup + fpsMeasurePeriod;
m_GuiText = GetComponent<Text>();
}
private void Update()
{
// measure average frames per second
m_FpsAccumulator++;
if (Time.realtimeSinceStartup > m_FpsNextPeriod)
{
m_CurrentFps = (int) (m_FpsAccumulator/fpsMeasurePeriod);
m_FpsAccumulator = 0;
m_FpsNextPeriod += fpsMeasurePeriod;
m_GuiText.text = string.Format(display, m_CurrentFps);
}
}
}
}