Unity 显示FPS

来源:互联网 发布:易知资本 编辑:程序博客网 时间:2024/05/16 19:41
using System.Collections;using System.Collections.Generic;using UnityEngine;public class FPS : MonoBehaviour {    float lastFPSTime;    int curFrameCount;    string curFPS = "";    void Start () {    }    void OnGUI()    {        OnShowFPS();    }    void OnShowFPS()    {        if (lastFPSTime == 0)        {            lastFPSTime = Time.time;            curFrameCount = Time.frameCount;            curFPS = "";        }        else        {            float curTime = Time.time;            if (curTime >= lastFPSTime + 1.0f)            {                int n = Time.frameCount - curFrameCount;                float dt = curTime - lastFPSTime;                curFPS = string.Format("FPS:{0:.00}", n / dt);                lastFPSTime = curTime;                curFrameCount = Time.frameCount;            }            GUI.skin.label.fontSize = 28;            GUI.contentColor = Color.white;            GUI.Label(new Rect(480, 10, 200, 100), curFPS);        }    }}
原创粉丝点击