在使用unity开发过程中,许多时候需要显示当前项目的帧率FPS,用于观察项目的流程度,那么如何计算FPS呢?请看下面代码演示:
public class FPSShow:MonoBehaviour
{
public Text[] ShowText;
private float accum;
private int frames;
void Start()
{
StartCoroutine(FPS());
}
void Update()
{
accum += Time.timeScale / Time.deltaTime;
++frames;
}
IEnumerator FPS()
{
// Infinite loop executed every "frenquency" secondes.
while (true)
{
// Update the FPS
float fps = accum / frames;
foreach (var ttt in ShowText)
{
ttt.text = fps.ToString("F1");
}
accum = 0.0F;
frames = 0;
yield return new WaitForSeconds(0.5f);
}
}
}
閱讀更多 夢牽魂之淚痕 的文章