unity 显示帧率

来源:互联网 发布:巨炮舰队扫矿软件 编辑:程序博客网 时间:2024/06/05 01:15


可参考Unity圣典点击打开链接

public class FPS: MonoBehaviour{    public static float f_Fps;    public float f_UpdateInterval = 0.5f; //每个0.5秒刷新一次    private float f_LastInterval; //游戏时间    private int i_Frames = 0;//帧数 void Awake()    {        Application.targetFrameRate = 60;    }    void OnGUI()    {        if (f_Fps > 50)        {            GUI.color = new Color(0, 1, 0);        }        else if (f_Fps > 40)        {            GUI.color = new Color(1, 1, 0);        }        else        {            GUI.color = new Color(1.0f, 0, 0);        }        GUI.Box(new Rect(10, 10, 100, 30), "FPS:" + f_Fps.ToString("f2"));    }    void Update()    {        ++i_Frames;        if (Time.realtimeSinceStartup > f_LastInterval + f_UpdateInterval)        {            f_Fps = i_Frames / (Time.realtimeSinceStartup - f_LastInterval);            i_Frames = 0;            f_LastInterval = Time.realtimeSinceStartup;        }     }}
就是如此简单...

0 0
原创粉丝点击