E_ElecCompetition/Electrical_inspectionCompet.../Assets/Script/MyFrameworkPure/Compoent/FPSDisplay.cs

49 lines
1.1 KiB
C#

using UnityEngine;
using System.Collections;
namespace MyFrameworkPure
{
/// <summary>
/// 显示帧率(OnGUI方式)
/// </summary>
public class FPSDisplay : MonoBehaviour
{
private float showFps;
private float showMsec;
private float fps = 0;
private float msec = 0;
void Start()
{
InvokeRepeating("UpdateView",0,1);
}
void Update()
{
msec = Time.smoothDeltaTime*1000;
fps = 1.0f/Time.smoothDeltaTime;
}
void UpdateView()
{
showFps = fps;
showMsec = msec;
}
void OnGUI()
{
int w = Screen.width, h = Screen.height;
GUIStyle style = new GUIStyle();
Rect rect = new Rect(0, 0, w, 50);
style.alignment = TextAnchor.UpperLeft;
style.fontSize = 50;
style.normal.textColor = Color.red;
//style.normal.background = Texture2D.blackTexture;
string text = string.Format("{0:0.0} ms ({1:0.} fps)", showMsec, showFps);
GUI.Label(rect, text, style);
}
}
}