1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
-
- using System;
- namespace UnityGameFramework.Runtime
- {
- public partial class DebuggerComponent
- {
- private sealed class FpsCounter
- {
- private float m_UpdateInterval;
- private float m_CurrentFps;
- private int m_Frames;
- private float m_Accumulator;
- private float m_TimeLeft;
- public FpsCounter(float updateInterval)
- {
- if (updateInterval <= 0f)
- {
- throw new ArgumentOutOfRangeException("Update interval is invalid.");
- }
- m_UpdateInterval = updateInterval;
- Reset();
- }
- public float UpdateInterval
- {
- get
- {
- return m_UpdateInterval;
- }
- set
- {
- if (value <= 0f)
- {
- throw new ArgumentOutOfRangeException("Update interval is invalid.");
- }
- m_UpdateInterval = value;
- Reset();
- }
- }
- public float CurrentFps
- {
- get
- {
- return m_CurrentFps;
- }
- }
- public void Update(float elapseSeconds, float realElapseSeconds)
- {
- m_Frames++;
- m_Accumulator += realElapseSeconds;
- m_TimeLeft -= realElapseSeconds;
- if (m_TimeLeft <= 0f)
- {
- m_CurrentFps = m_Accumulator > 0f ? m_Frames / m_Accumulator : 0f;
- m_Frames = 0;
- m_Accumulator = 0f;
- m_TimeLeft += m_UpdateInterval;
- }
- }
- private void Reset()
- {
- m_CurrentFps = 0f;
- m_Frames = 0;
- m_Accumulator = 0f;
- m_TimeLeft = 0f;
- }
- }
- }
- }
|