이상윤

FPS Check

1 +using System.Collections;
2 +using System.Collections.Generic;
3 +using UnityEngine;
4 +
5 +public class FPS_Check : MonoBehaviour
6 +{
7 + [Range(1, 100)]
8 + public int fFont_Size;
9 + [Range(0, 1)]
10 + public float Red, Green, Blue;
11 +
12 + float deltaTime = 0.0f;
13 +
14 + private void Start()
15 + {
16 + fFont_Size = fFont_Size == 0 ? 50 : fFont_Size;
17 + }
18 +
19 + void Update()
20 + {
21 + deltaTime += (Time.unscaledDeltaTime - deltaTime) * 0.1f;
22 + }
23 +
24 + void OnGUI()
25 + {
26 + int w = Screen.width, h = Screen.height;
27 +
28 + GUIStyle style = new GUIStyle();
29 +
30 + Rect rect = new Rect(0, 0, w, h * 2 / 100);
31 + style.alignment = TextAnchor.UpperLeft;
32 + style.fontSize = h * 2 / fFont_Size;
33 + style.normal.textColor = new Color(Red, Green, Blue, 1.0f);
34 + float msec = deltaTime * 1000.0f;
35 + float fps = 1.0f / deltaTime;
36 + string text = string.Format("{0:0.0} ms ({1:0.} fps)", msec, fps);
37 + GUI.Label(rect, text, style);
38 + }
39 +}
...\ No newline at end of file ...\ No newline at end of file