FPS interv

using UnityEngine;
using System.Collections;

public class showFPSManager : MonoBehaviour 
{    
    private float FPS_updateInterval = 0.5F;
    private double FPS_lastInterval;
    private int FPS_frames = 0;
    private float FPS_fps;
    private string frameText;
    // Use this for initialization
    void Start () 
    {
        FPS_lastInterval = Time.realtimeSinceStartup;
        FPS_frames = 0;    
    }
    
    // Update is called once per frame
    void Update () 
    {
        frameText= "FPS: " + CalFPS().ToString("f2");
    }
    
    public float CalFPS()
    {
         ++FPS_frames;
        float timeNow = Time.realtimeSinceStartup;
        if (timeNow > FPS_lastInterval + FPS_updateInterval) {
            FPS_fps = (float)(FPS_frames / (timeNow - FPS_lastInterval));
            FPS_frames = 0;
            FPS_lastInterval = timeNow;
        }
        
        return FPS_fps;
    }
    
    void OnGUI()
    {
        GUI.Label(new Rect(10,10,80,20),frameText);
    }
}

 该脚本直接挂在uiroot里面的camera

posted @ 2013-10-29 14:51  小薇林  阅读(177)  评论(0编辑  收藏  举报