码迷,mamicode.com
首页 > 其他好文 > 详细

An FPS counter.

时间:2016-01-06 15:51:10      阅读:176      评论:0      收藏:0      [点我收藏+]

标签:

using UnityEngine;
using System.Collections;

// An FPS counter.
// It calculates frames/second over each updateInterval,
// so the display does not keep changing wildly.
public class Test : MonoBehaviour {
    public float updateInterval = 0.5F;
    private double lastInterval;
    private int frames = 0;
    private float fps;
    void Start() {
        lastInterval = Time.realtimeSinceStartup;
        frames = 0;
    }
    void OnGUI() {
        GUILayout.Label("fps:" + fps.ToString("f2"));
    }
    void Update() {
        ++frames;
        float timeNow = Time.realtimeSinceStartup;
        if (timeNow > lastInterval + updateInterval) {
            fps = (float)(frames / (timeNow - lastInterval));
            frames = 0;
            lastInterval = timeNow;
        }
    }
}

An FPS counter.

标签:

原文地址:http://www.cnblogs.com/panyingying/p/5105571.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!