1.獲取適合時間內的FPS平均值,此處爲0.5s內的平均幀數
{
public bool showFPS = true;
private float accum = 0.0f; // FPS accumulated over the interval
private float frames = 0f; // Frames drawn over the interval
private float timeleft; // Left time for current interval
void Start () {
InvokeRepeating("SetType",0.1f,0.5f);
}
if (showFPS){
timeleft -= Time.deltaTime;
accum += Time.timeScale/Time.deltaTime;
++frames;
if( timeleft <= 0.0f )
{
// display two fractional digits (f2 format)
timeleft = updateInterval;
accum = 0.0f;
frames = 0f;
}
} else {
textObj_fps.text = "";
}
void SetType(){
if (textObj_fps != null && accum > 0f && frames > 0f){
textObj_fps.text = "FPS: "+(accum/frames).ToString("f0");
}
}
{
InvokeRepeating("SetType",0.1f,0.1f);
}
void SetType(){
if (textObj_fps != null){
textObj_fps.text = "FPS: " + (Time.timeScale / Time.deltaTime).ToString("f0");
}
}