您的位置:首页 > 移动开发 > Unity3D

unity 显示帧率

2015-09-13 21:01 483 查看

可参考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;
}
}

}
就是如此简单...
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: