Unity Game Viewer에서 프레임을 체크할 수 있는 코드이다.
단점으로는 실제 빌드를 하였을때와 에디터 상에서 프레임의 차이가 발생되는 문제가 있으며,
단순하게 에디터 상에서 확인하기에는 이만한 친구가 없다.
* 해당 코드의 경우 구글링을 통해서 습득한 코드이기 때문에 최초 작성자는 알 수 없다.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FrameChecker : MonoBehaviour
{
[Range(1, 200)]
public int fFont_Size;
[Range(0, 1080)]
public float xPos;
[Range(0, 2400)]
public float yPos;
[Range(0, 1)]
public float Red, Green, Blue;
float deltaTime = 0.0f;
private void Start()
{
}
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(xPos, yPos, w / 2, h * 2 / 100);
style.alignment = TextAnchor.UpperLeft;
style.fontSize = h * 2 / fFont_Size;
style.normal.textColor = new Color(Red, Green, Blue, 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);
}
}
'Unity > Script' 카테고리의 다른 글
| [Unity] Frame Checker On Editor (0) | 2024.06.18 |
|---|---|
| [Unity] Camare Position Move v1.0 (1) | 2024.06.18 |