Android
2014.06.15 06:44
[ 유니티3D엔진 ] FPS 프레임 조절
조회 수 129101 추천 수 0 댓글 0
using UnityEngine;
using System.Collections;
public class Fps : MonoBehaviour
{
public UILabel FpsLabel;
public float updateInterval = 0.5F;
private float accum = 0; // FPS accumulated over the interval
private int frames = 0; // Frames drawn over the interval
private float timeleft; // Left time for current interval
void Awake()
{
QualitySettings.vSyncCount = 0;
Application.targetFrameRate = 60;
}
void Start()
{
timeleft = updateInterval;
}
void Update()
{
timeleft -= Time.deltaTime;
accum += Time.timeScale / Time.deltaTime;
++frames;
if (timeleft <= 0.0)
{
float fps = accum / frames;
string format = System.String.Format("{0:F2} FPS", fps);
FpsLabel.text = format;
timeleft = updateInterval;
accum = 0.0F;
frames = 0;
}
}
}
QualitySettings.vSyncCount = 0;
Application.targetFrameRate = 60;
FrameRate은 기본 적으로 60으로 되어 있고, QualitySettings.vSyncCount = 0; 으로 해줘야지만 동작한다.