ãUnityãiPhoneX対å¿ã®ç½ ããªããCanvasã®Anchorããããåé¡ã®è§£æ±ºç
æ¦è¦
é
ãã°ããªãããä»éçºä¸ã®æ°ä½ã²ã¼ã ã§iPhoneX対å¿ãè¡ããã¨ã«ãªãã¾ããã
ããããæ¤ç´¢ããã¨ããããªæ
å ±ã溢ãã¦ãã¾ãããã¾ãã¯å
¬å¼æ
å ±ãã»ã»ã»ã¨ãããã¨ã§Unityå
¬å¼ã®ãµã³ãã«ãå
ã«å¯¾å¿ãé²ããçµæãè¦äºã«å°é·ãè¸ãã ã®ã§å
±æãã¦ããã¾ãã
Unityå ¬å¼æ å ±
iPhoneXã®ç»é¢åé¡ã¯æ¥ççã«ãããªãè¿·æãªãã®ã§ããã
Unityããã¡æ©ããã®åé¡ã«åãåããããããªãªã¼ã¹ãçµã¦æ£å¼ã«SafeAreaã«å¯¾å¿ãã¦ãã¾ãã
helpdesk.unity3d.co.jp
Unity - Scripting API: Screen.safeArea
ä¸ã¤ç®ã®ãªã³ã¯ããUnityã®ãµã³ãã«ãã¿ããã¨ãã§ãã¾ãã
ãã®ãµã³ãã«ã®å
容ã¯ãè¦ç´ããã¨ä»¥ä¸ã®éãã§ãã
void ApplySafeArea()
{
var area = Screen.safeArea;
var anchorMin = area.position;
var anchorMax = area.position + area.size;
anchorMin.x /= Screen.width;
anchorMin.y /= Screen.height;
anchorMax.x /= Screen.width;
anchorMax.y /= Screen.height;
panel.anchorMin = anchorMin;
panel.anchorMax = anchorMax;
}
ãµã³ãã«ã®ç½
ä¸è¨ã®ãµã³ãã«ã§ãããç¹å®ã®ç¶æ³ä¸ã§ä¸å
·åãå¼ãèµ·ããã¾ãã
ç§ãééããä¸å
·åã¯ã以ä¸ã®ãããªãã®ã§ãã
- Canvasã®Anchorãå³ä¸ã«ããã
- ä¸é¨ã®UIãææ» ãç¹°ãè¿ãããã«ãªã
åå
ä¸è¨ã«æ¸ããä¸å
·åã¯ãScreen.SetResolutionã§ç»é¢è§£å度ãå¤æ´ãã¦ããå ´åã«çºçãã¾ãã
åå ã¯ãanchorMin/anchorMaxã®åè¦ç´ ãScreen.width/heightã§æ£è¦åãã¦ããé¨åã§ãã
Screen.width/heightã¯ãSetResolution以éã¯æå®ãã解å度ãè¿ãããã«ãªãã¾ãã
ããããScreen.safeAreaã§è¿ãããå¤ã¯ãã£ã¹ãã¬ã¤ã®è§£å度ã®ãããæ£è¦åã®è¨ç®ãçããCanvasã®Anchorãå³ä¸ã«ããã¦ãã¾ãããã§ãã
対å¿
ããã¤ã¹ã®ãã£ã¹ãã¬ã¤è§£å度ãDisplayã¯ã©ã¹ããåå¾ãããã®å¤ã§æ£è¦åãããã¨ã§åé¡ã解決ãããã¨ãã§ãã¾ãã
void ApplySafeArea() { var area = Screen.safeArea; var display = Display.displays[0]; var screenSize = new Vector2Int(display.systemWidth, display.systemHeght); var anchorMin = area.position; var anchorMax = area.position + area.size; anchorMin.x /= screenSize.x; anchorMin.y /= screenSize.y; anchorMax.x /= screenSize.x; anchorMax.y /= screenSize.y; panel.anchorMin = anchorMin; panel.anchorMax = anchorMax; }