【Unity】フレームレートの計算
よくあるフレームレート(FPS)計測用の実装例。
public class Fps
{
//測定用
private float m_fps;
private float m_updateInterval = 1.0f;
private float m_accumulated = 0.0f;
private float m_timeUntilNextInterval = 0.0f;
private int m_numFrames = 0;
public float GetFPS()
{
return m_fps;
}
public void Update()
{
var deltaTime = Time.deltaTime;
m_timeUntilNextInterval -= deltaTime;
m_accumulated += Time.timeScale / deltaTime;
++m_numFrames;
if (m_timeUntilNextInterval <= 0.0f)
{
m_fps = m_accumulated / m_numFrames;
m_timeUntilNextInterval = m_updateInterval;
m_accumulated = 0.0f;
m_numFrames = 0;
}
}
}
どこかで毎フレームUpdateを呼んであげると良いです。