Unity 顯示幀率的方法
阿新 • • 發佈:2019-01-27
public class DeltaFPS { private float _UpdateInterval = 0.1f;//更新週期 private float _Accum; private int _Frames; private float _Timeleft; private string _Fps; //幀率 public void Init() { Reset(); } private void Reset() { _Timeleft = updateInterval; _Accum = 0.0f; +Frames = 0; } public void Update() { _Timeleft -= Time.deltaTime; _Accum += Time.timeScale / Time.deltaTime; ++_Frames; if (_Timeleft <= 0) { _Fps = (_Accum / _Frames).ToString("f2"); Reset(); } } public void OnGUI() { GUILayout.Label(_Fps); } }