Last active
August 18, 2023 11:51
-
-
Save RimuruDev/271d8d8b167420c4c2c092459b228bb4 to your computer and use it in GitHub Desktop.
Как определить ориентацию экрана JS Unity Webgl. Определить iPad ориентацию Unity. RimuruDev.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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