[Unity] 해상도 조절 함수
- 유니티
- 2018. 8. 13. 05:51
void ResizeSpriteToScreen(GameObject theSprite, tk2dCamera theCamera, int fitToScreenWidth, int fitToScreenHeight)
{
MeshRenderer sr = theSprite.GetComponent<MeshRenderer>();
theSprite.transform.localScale = new Vector3(1, 1, 1);
float width = sr.bounds.size.x;
float height = sr.bounds.size.y;
float worldScreenHeight = (float)(theCamera.CameraSettings.orthographicSize * 2.0);
float worldScreenWidth = (float)(worldScreenHeight / Screen.height * Screen.width);
if (fitToScreenWidth != 0)
{
Vector2 sizeX = new Vector2(worldScreenWidth / width / fitToScreenWidth, theSprite.transform.localScale.y);
theSprite.transform.localScale = sizeX;
}
if (fitToScreenHeight != 0)
{
Vector2 sizeY = new Vector2(theSprite.transform.localScale.x, worldScreenHeight / height / fitToScreenHeight);
theSprite.transform.localScale = sizeY;
}
}
'유니티' 카테고리의 다른 글
[Unity] Coroutine Delayed Calls (0) | 2018.08.27 |
---|---|
[유니티] 프로젝트 2개 이상 실행하기 (0) | 2018.08.18 |
[Unity] StopCoroutine이 먹히지 않을 때 (0) | 2018.08.08 |
[Unity] Vector3 포지션이 원하는 방향으로 가지 않을 때 (0) | 2018.08.05 |
[Unity] Ignoring asset refresh of ******* because the file or its directory couldn't be found! (0) | 2018.07.30 |
이 글을 공유하기