浏览代码

Added avg, min, max frametime to the mini profiler

/demo-work-customrenderer
André McGrail 5 年前
当前提交
6378ffd1
共有 1 个文件被更改,包括 30 次插入1 次删除
  1. 31
      Assets/Scripts/System/MiniProfiler.cs

31
Assets/Scripts/System/MiniProfiler.cs


private string m_statsLabel;
private GUIStyle m_style;
private float[] m_frameTimes = new float[5000];
private int m_totalFrames = 0;
private float m_minFrameTime = 1000f;
private float m_maxFrameTime = 0f;
internal class RecorderEntry
{
public string name;

m_AccDeltaTime += Time.unscaledDeltaTime;
m_frameCount++;
m_frameTimes[(int) Mathf.Repeat(m_totalFrames, 5000)] = Time.unscaledDeltaTime;
int frameFactor = Mathf.Clamp(m_totalFrames, 0, 5000);
float m_averageFrameTime = 0f;
for (int i = 0; i < frameFactor; i++)
{
m_averageFrameTime += m_frameTimes[i];
}
if (m_frameCount > 10)
{
m_minFrameTime = Time.unscaledDeltaTime < m_minFrameTime ? Time.unscaledDeltaTime : m_minFrameTime;
m_maxFrameTime = Time.unscaledDeltaTime > m_maxFrameTime ? Time.unscaledDeltaTime : m_maxFrameTime;
}
// get timing & update average accumulators
for (int i = 0; i < recordersList.Length; i++)
{

m_statsLabel += $" Draws:{avgDraw:F2}ms\n";
m_statsLabel += $" PostProcessing:{avgPost:F2}ms\n";
m_statsLabel += $"Total: {(m_AccDeltaTime * 1000.0f * ooFrameCount):F2}ms ({(int)(((float)m_frameCount) / m_AccDeltaTime)} FPS)\n";
float frameMulti = 1f / frameFactor;
m_statsLabel += $"Average:{(m_averageFrameTime * 1000f * frameMulti):F2}ms\n";
m_statsLabel += $"Minimum:{m_minFrameTime * 1000f:F2}ms\n";
m_statsLabel += $"Maximum:{m_maxFrameTime * 1000f:F2}ms\n";
m_totalFrames++;
}
void OnGUI()

正在加载...
取消
保存