46 lines
724 B
C#
46 lines
724 B
C#
using System;
|
|
using UnityEngine;
|
|
|
|
[Serializable]
|
|
public class UnluckFPS : MonoBehaviour
|
|
{
|
|
public TextMesh _textMesh;
|
|
|
|
public float updateInterval;
|
|
|
|
private float accum;
|
|
|
|
private int frames;
|
|
|
|
private float timeleft;
|
|
|
|
public UnluckFPS()
|
|
{
|
|
updateInterval = 0.5f;
|
|
}
|
|
|
|
public virtual void Start()
|
|
{
|
|
timeleft = updateInterval;
|
|
_textMesh = (TextMesh)transform.GetComponent(typeof(TextMesh));
|
|
}
|
|
|
|
public virtual void Update()
|
|
{
|
|
timeleft -= Time.deltaTime;
|
|
accum += Time.timeScale / Time.deltaTime;
|
|
frames++;
|
|
if (!(timeleft > 0f))
|
|
{
|
|
_textMesh.text = "FPS " + (accum / (float)frames).ToString("f2");
|
|
timeleft = updateInterval;
|
|
accum = 0f;
|
|
frames = 0;
|
|
}
|
|
}
|
|
|
|
public virtual void Main()
|
|
{
|
|
}
|
|
}
|