Skip to content

Instantly share code, notes, and snippets.

@RimuruDev
Last active August 18, 2023 11:51
Show Gist options
  • Save RimuruDev/271d8d8b167420c4c2c092459b228bb4 to your computer and use it in GitHub Desktop.
Save RimuruDev/271d8d8b167420c4c2c092459b228bb4 to your computer and use it in GitHub Desktop.
Как определить ориентацию экрана JS Unity Webgl. Определить iPad ориентацию Unity. RimuruDev.
window.addEventListener('orientationchange', function ()
{
if (/iPhone|iPad|iPod|Android/i.test(navigator.userAgent) && typeof screen.orientation !== 'undefined')
{
switch (screen.orientation.type)
{
case 'portrait-primary':
case 'portrait-secondary':
canvas.style.background = "url('portrait.png') center / cover";
break;
case 'landscape-primary':
case 'landscape-secondary':
canvas.style.background = "url('background.png') center / cover";
break;
default:
canvas.style.background = "url('background.png') center / cover";
}
}
else
canvas.style.background = "url('background.png') center / cover";
});
if (/iPhone|iPad|iPod|Android/i.test(navigator.userAgent))
{
container.className = "unity-mobile";
if (screen.orientation.type === 'portrait-primary')
canvas.style.background = "url('portrait.png') center / cover";
if (screen.orientation.type === 'landscape-primary')
canvas.style.background = "url('background.png') center / cover";
}
else
canvas.style.background = "url('background.png') center / cover";
loadingCover.style.display = "";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment