35 lines
950 B
C#
35 lines
950 B
C#
|
|
using UnityEngine;
|
||
|
|
using TMPro;
|
||
|
|
|
||
|
|
namespace Elbyss.Optimization
|
||
|
|
{
|
||
|
|
public class PerformanceHUD : MonoBehaviour
|
||
|
|
{
|
||
|
|
private float deltaTime = 0.0f;
|
||
|
|
private string displayFormat = "{0:0.0} ms ({1:0.} fps)";
|
||
|
|
|
||
|
|
private void Update()
|
||
|
|
{
|
||
|
|
deltaTime += (Time.unscaledDeltaTime - deltaTime) * 0.1f;
|
||
|
|
}
|
||
|
|
|
||
|
|
private void OnGUI()
|
||
|
|
{
|
||
|
|
int w = Screen.width, h = Screen.height;
|
||
|
|
|
||
|
|
GUIStyle style = new GUIStyle();
|
||
|
|
|
||
|
|
Rect rect = new Rect(10, 10, w, h * 2 / 100);
|
||
|
|
style.alignment = TextAnchor.UpperLeft;
|
||
|
|
style.fontSize = h * 2 / 50;
|
||
|
|
style.normal.textColor = new Color(0.0f, 1.0f, 0.5f, 1.0f);
|
||
|
|
|
||
|
|
float msec = deltaTime * 1000.0f;
|
||
|
|
float fps = 1.0f / deltaTime;
|
||
|
|
string text = string.Format(displayFormat, msec, fps);
|
||
|
|
|
||
|
|
GUI.Label(rect, text, style);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|