1.获取适合时间内的FPS平均值,此处为0.5s内的平均帧数
public class FPS : MonoBehaviour
{
{
public UnityEngine.UI.Text textObj_fps;
public bool showFPS = true;
public bool showFPS = true;
private float updateInterval = 0.5f;
private float accum = 0.0f; // FPS accumulated over the interval
private float frames = 0f; // Frames drawn over the interval
private float timeleft; // Left time for current interval
private float accum = 0.0f; // FPS accumulated over the interval
private float frames = 0f; // Frames drawn over the interval
private float timeleft; // Left time for current interval
void Start () {
InvokeRepeating("SetType",0.1f,0.5f);
}
void LateUpdate () {
// CALCULATE FPS
if (showFPS){
timeleft -= Time.deltaTime;
accum += Time.timeScale/Time.deltaTime;
++frames;
if (showFPS){
timeleft -= Time.deltaTime;
accum += Time.timeScale/Time.deltaTime;
++frames;
// Interval ended - update GUI text and start new interval
if( timeleft <= 0.0f )
{
if( timeleft <= 0.0f )
{