FPS计算New

时间:2014-10-11 18:52:47   收藏:0   阅读:279
using UnityEngine;
using System.Collections;

public class CarGUI : MonoBehaviour
{
    private const float FPS_UPDATE_INTERVAL = 0.5f;
    private float fpsAccum = 0;
    private int fpsFrames = 0;
    private float fpsTimeLeft = FPS_UPDATE_INTERVAL;
    private float fps = 0;

    void Update()
    {
        fpsTimeLeft -= Time.deltaTime;
        fpsAccum += Time.timeScale / Time.deltaTime;
        fpsFrames++;

        if (fpsTimeLeft <= 0)
        {
            fps = fpsAccum / fpsFrames;
            fpsTimeLeft = FPS_UPDATE_INTERVAL;
            fpsAccum = 0;
            fpsFrames = 0;
        }
    }

    void OnGUI()
    {
        GUILayout.BeginArea(new Rect(5, 5, 500, 500));
        GUILayout.Label("Arrows: movement\nCtrl: flip car");
        GUILayout.Label("FPS: " + fps.ToString("f1"));
        GUILayout.EndArea();
    }
}

 

原文:http://www.cnblogs.com/123ing/p/4019562.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!