๋ด๊ฐ ๋ง๋ ๊ฒ์์ย ๋ชฉํ framerate๊ฐ 60์ธ๋ฐ,ย ๊ธฐ๊ธฐ ์ฑ๋ฅ์ด ๋ฎ์ ๊ฒฝ์ฐ frame ๋๋์ด ๊ฝค ์ฌํด.
์๋ ์ปจํธ๋กค์ด ์ค์ํ ๊ฒ์์ด๋ผ framedrop์ด ์ฌํ ๊ฒฝ์ฐ, ๋ด๊ฐ ํ๋๋ผ๋ ํ๋ ์ด๊ฐ ํ๋ค๋๋ผ๊ตฌ.
๊ทธ๋์ย resolution์ ๋ฐ๋ฅธ frame์ ์ธก์ ํด๋ดค๋๋ฐ ์๊ทผ resolution์ ๋ฐ๋ผ์ frame์ด ์ฐจ์ด๊ฐ ๋ง์ด๋.
๊ทธ๋์ ์๋์ ๊ฐ์ด ๊ฒ์ ์์ํ ๋ resolution ์๋์ผ๋ก ๋ณ๊ฒฝํด์ฃผ๋ ์ฝ๋ ๋ง๋ค์๋๋ฐ,ย
ํน์ ํ์ํ ์ฌ๋์ ์จ๋ณด๊ณ ย (๋ฌผ๋ก ์ ๋ง๋ ์ฝ๋๋ ์๋. ๊ทธ๊ฑธ ๊ฐ์ํด ใ ใ )
์๋ ์ฝ๋์์ ๋ ๊ฐ์ ํ ์ ์์ผ๋ฉด ์๊ธฐํด์ฃผ๋ฉด ๋ฐ์ํด์ ๋ด ๊ฒ์์ ์ง์ด๋ฃ๊ฒ ์!!
public class ResolutionMgr : MonoBehaviour
{
private int _minHeightRes = 1220;
private int _resolutionChangeAmt = 100;
private int _targetFrameRate = 55;
private float _frameCheckInterval = 2f;
private float _frameRate;
private void Awake()
{
Application.targetFrameRate = 60;
SetAutoResolution();
}
public void SetAutoResolution()
{
StartCoroutine(AdjustResolutionCoroutine());
}
IEnumerator AdjustResolutionCoroutine()
{
// Max ํด์๋
int maxHeightRes = Screen.height;
// ํ์ฌ ์ค์ ๋ ํด์๋
int height = Screen.currentResolution.height;
// ํด์๋ ๋น์จ
float screenRatio = (float) Screen.currentResolution.width / Screen.currentResolution.height;
// ์ด๊ธฐ ์๊ฐ๊ณผ ๋์ ํ๋ ์ ์ด๊ธฐํ
float timer = 0f;
int totalFrames = 0;
// ์ฒ์ 1.5์ด ์ดํ์ ๊ณ์ฐ ์์
yield return new WaitForSeconds(1.5f);
while (true)
{
// ํ๋ ์ ์ ๊ฐฑ์
totalFrames++;
float deltaTime = Time.deltaTime;
timer += deltaTime;
if (timer >= _frameCheckInterval)
{
//float frameRate = totalFrames / timer;
_frameRate = totalFrames / timer;
totalFrames = 0;
timer = 0f;
// ํ๊ฒ ํ๋ ์ ์๋์ ๋๋ฌํ๋ฉด ํด์๋ ์กฐ์ ์ข ๋ฃ
if (_frameRate >= _targetFrameRate || height <= _minHeightRes)
{
yield break;
}
// ํ๋ ์ ์๋๊ฐ ํ๊ฒ์ ๋ฏธ๋ฌํ๋ ๊ฒฝ์ฐ, ํด์๋๋ฅผ ๊ฐ์
if (_frameRate <= 20)
{
height = Mathf.Clamp(height - _resolutionChangeAmt * 4, _minHeightRes, maxHeightRes);
}
else if (_frameRate <= 40)
{
height = Mathf.Clamp(height - _resolutionChangeAmt * 2, _minHeightRes, maxHeightRes);
}
else
{
height = Mathf.Clamp(height - _resolutionChangeAmt, _minHeightRes, maxHeightRes);
}
int width = Mathf.RoundToInt(screenRatio * height);
SetResolution(width, height);
}
yield return null;
}
}
private void SetResolution(int width, int height)
{
Screen.SetResolution(width, height, Screen.fullScreen);
}
}
๋ ๋ก๋น๋ ๊ฒ์์ด ๋๋ ์ ธ ์์ด์ ๊ฒ์ ์์ ์ 10์ด ํ๋ก ๋ณ๊ฒฝํด์ ์จ๋ณด๋๋ฐ ๋๋ฌด ์ข๋ค!!! ๊ณ ๋ง์!!!
์ ๋ํฐ ๊ณต์ ํจํค์ง์ค์ ๋น์ทํ ์ญํ ํด์ฃผ๋๊ฒ Adaptive Performance๋ผ๊ณ ์์๋๊ฒ๊ฐ์๋ฐ ์ง์ ์จ๋ณด์ง ์์์ ๋ชจ๋ฅด๊ฒ ๋ค