public void InitializeResolutionSettings(float targetaspect)
{
// determine the game window's current aspect ratio
float windowaspect = (float)Screen.width / (float)Screen.height;
// current viewport height should be scaled by this amount
scaleHeight = windowaspect / targetaspect;
// obtain camera component so we can modify its viewport
Camera camera = Camera.main;
// if scaled height is less than current height, add letterbox
if (scaleHeight < 1.0f)
{
Rect rect = camera.rect;
rect.width = 1.0f;
rect.height = scaleHeight;
rect.x = 0;
rect.y = (1.0f - scaleHeight) / 2.0f;
heightShift = rect.y;
//camera.rect = rect;
}
else // add pillarbox
{
scaleWidth = 1.0f / scaleHeight;
scaleHeight = 1;
Rect rect = camera.rect;
rect.width = scaleWidth;
rect.height = 1.0f;
rect.x = (1.0f - scaleWidth) / 2.0f;
rect.y = 0;
widthShift = rect.x;
//camera.rect = rect;
}
}