在这里插入代码片`#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`
Unity计算fps
最新推荐文章于 2024-10-11 11:50:35 发布