Example #1
0
        // Time per frame varies wildly, so we average a bit and display that.
        private static void UpdateFrameTime()
        {
            if (Event.current.type != EventType.Repaint)
            {
                return;
            }

            float frameTime  = UnityStats.frameTime;
            float renderTime = UnityStats.renderTime;

            m_ClientTimeAccumulator += frameTime;
            m_RenderTimeAccumulator += renderTime;
            if (Application.targetFrameRate <= 0 || !Unsupported.IsEditorPlayerLoopWaiting())
            {
                m_MaxTimeAccumulator += Mathf.Max(frameTime, renderTime);
            }
            else
            {
                m_MaxTimeAccumulator += Unsupported.GetFrameTimeCalculatedForEachEditorPlayerLoop();
            }
            ++m_FrameCounter;

            bool needsTime = m_ClientFrameTime == 0.0f && m_RenderFrameTime == 0.0f;
            bool resetTime = m_FrameCounter > 30 || m_ClientTimeAccumulator > 0.3f || m_RenderTimeAccumulator > 0.3f;

            if (needsTime || resetTime)
            {
                m_ClientFrameTime = m_ClientTimeAccumulator / m_FrameCounter;
                m_RenderFrameTime = m_RenderTimeAccumulator / m_FrameCounter;
                m_MaxFrameTime    = m_MaxTimeAccumulator / m_FrameCounter;
            }
            if (resetTime)
            {
                m_ClientTimeAccumulator = 0.0f;
                m_RenderTimeAccumulator = 0.0f;
                m_MaxTimeAccumulator    = 0.0f;
                m_FrameCounter          = 0;
            }
        }