[Unity] 해상도 조절 함수

    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;

        }

    }

이 글을 공유하기

댓글

Designed by JB FACTORY