iThis is a problem that you encounter when porting Unity titles developed for iOS and Android as Windows Store apps.
Windows 8.1 allows you to change the window size of the Windows Store app, but when you run the Windows Store app that you built from Unity and change the window size, both sides of the screen appear disconnected.
US>Full Screen Status
Changed window size
What code should I write in Unity C#Script to keep the original aspect ratio intact?
windows unity3d windows-store-apps
To work as expected, add C#Script to one of the GameObjects that will not be deleted during play, such as Terrain. Implement the UnityEngine.WSA.Application.windowSizeChanged event handler.For some reason, it is not mentioned in the Unity document.
Assuming that the main camera is named mainCamera, you can resolve it with the following code: Keep the aspect in place when the device is turned.
http://gamedesigntheory.blogspot.jp/2010/09/controlling-aspect-ratio-in-unity.html Reference the code in the .
void Start()
{
# if UNITY_METRO
UnityEngine.WSA.Application.windowSizeChanged+=Application_windowSizeChanged;
#endif
}
void Application_windowSizeChanged(int width, int height)
{
// set the desired aspect ratio (the values in this example are)
// hard-coded for 16:9, but you could make them into public
// variables installed so you can set them at design time)
float targetaspect = 16.0f/9.0f;
// determine the game window's current aspect ratio
float windowaspect=(float)width/(float)height;
// current viewport height should be scaled by this amount
float scaleheight=windowaspect/targetaspect;
// obtain camera component so we can modify its viewport
Camera camera=GameObject.Find("mainCamera").camera;
if(camera==null)
{
return;
}
// if scaled height is less than current height, add letterbox
if(scaleheight<1.0f)
{
Correct = camera.rect;
rect.width = 1.0f;
rect.height = scaleheight;
rect.x = 0;
rect.y = (1.0f-scaleheight)/2.0f;
camera.rect=rect;
}
else//add pillarbox
{
float scalewidth = 1.0f/scaleheight;
Correct = camera.rect;
rect.width = scalewidth;
rect.height=1.0f;
rect.x = (1.0f-scalewidth)/2.0f;
rect.y = 0;
camera.rect=rect;
}
}
577 PHP ssh2_scp_send fails to send files as intended
566 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
596 GDB gets version error when attempting to debug with the Presense SDK (IDE)
884 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
© 2024 OneMinuteCode. All rights reserved.