1 using System;
2 using
UnityEngine;
3
4 namespace
UnityStandardAssets.Utility
5 {
6     
[RequireComponent(typeof (GUIText))]
7     
public class FPSCounter : MonoBehaviour
8     {
9         
const float fpsMeasurePeriod = 0.5f;
10         
private int m_FpsAccumulator = 0;
11         
private float m_FpsNextPeriod = 0;
12         
private int m_CurrentFps;
13         
const string display = "{0} FPS";
14         
private GUIText m_GuiText;
15
16
17         
private void Start()
18         {
19             m_FpsNextPeriod = Time.realtimeSinceStartup + fpsMeasurePeriod;
20             m_GuiText = GetComponent<GUIText>();
21         }
22
23
24         
private void Update()
25         {
26             
// measure average frames per second
27             m_FpsAccumulator++;
28             
if (Time.realtimeSinceStartup > m_FpsNextPeriod)
29             {
30                 m_CurrentFps = (
int) (m_FpsAccumulator/fpsMeasurePeriod);
31                 m_FpsAccumulator =
0;
32                 m_FpsNextPeriod += fpsMeasurePeriod;
33                 m_GuiText.text =
string.Format(display, m_CurrentFps);
34             }
35         }
36     }
37 }


measure average frames per second



Gõ tìm kiếm nhanh...