IT 이모저모
FPS 표시
exien
2018. 2. 28. 15:06
유니티로 게임을 개발할때 성능테스트 할때 FPS를 주로 봅니다.
간단하게 FPS를 게임 화면에 표시 할때 사용하면 좋습니다.
public class FpsGui : MonoBehaviour { float deltaTime = 0.0f; void Update() { deltaTime += (Time.unscaledDeltaTime - deltaTime) * 0.1f; } void OnGUI() { int w = Screen.width, h = Screen.height; GUIStyle style = new GUIStyle(); Rect rect = new Rect(0, 0, w, h * 2 / 100); style.alignment = TextAnchor.UpperLeft; style.fontSize = h * 2 / 100; style.normal.textColor = new Color(0.0f, 0.0f, 0.5f, 1.0f); float msec = deltaTime * 1000.0f; float fps = 1.0f / deltaTime; string text = string.Format("{0:0.0} ms ({1:0.} fps)", msec, fps); GUI.Label(rect, text, style); } }