๋‚ด๊ฐ€ ๋งŒ๋“  ๊ฒŒ์ž„์˜ย ๋ชฉํ‘œ 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);

}

}