Unity计算fps

旧巷老猫 提交于 2019-12-27 03:02:49
在这里插入代码片`#if UNITY_EDITOR
public class ShowFps:MonoBehaviour
{
    public float updateInterval = .5f;
    int cnt = 0;
    string stringFps;
    float accum;
    private void Update()
    {
        accum += Time.timeScale / Time.deltaTime; //求平均值
        updateInterval -= Time.deltaTime;
        cnt++;
        if(updateInterval<0)
        {
            double fps = accum / cnt;
            updateInterval = .5f;
            accum = 0;
            stringFps = $"{fps} fps";
            cnt = 0;
        }
    }
    private void OnGUI()
    {
        GUIStyle guistyle = GUIStyle.none;
        guistyle.fontSize = 60;
        guistyle.normal.textColor = Color.red;
        guistyle.alignment = TextAnchor.UpperLeft;
        Rect rt = new Rect(80, 80, 100, 100);
        GUI.Label(rt, stringFps, guistyle);
    }
}
#endif`
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!