블로그 이미지
Every unexpected event is a path to learning for you.

카테고리

분류 전체보기 (2737)
Unity3D (817)
Programming (474)
Server (33)
Unreal (4)
Gamebryo (56)
Tip & Tech (228)
협업 (58)
3DS Max (3)
Game (12)
Utility (136)
Etc (96)
Link (32)
Portfolio (19)
Subject (90)
iOS,OSX (53)
Android (14)
Linux (5)
잉여 프로젝트 (2)
게임이야기 (3)
Memories (20)
Interest (38)
Thinking (38)
한글 (30)
PaperCraft (5)
Animation (408)
Wallpaper (2)
재테크 (18)
Exercise (3)
나만의 맛집 (3)
냥이 (10)
육아 (16)
Total
Today
Yesterday
04-20 00:00

You can check against UnityEngine.iOS.Device.generation

Note that you'll need Unity 2017.2 or higher to detect iPhone X. 

Unity 5.6.5f1 also seems to support the iPhoneX enum, even though it's not listed in the 5.6 docs. 

  1. bool deviceIsIphoneX = UnityEngine.iOS.Device.generation == UnityEngine.iOS.DeviceGeneration.iPhoneX;
  2. if (deviceIsIphoneX) {
  3. // Do something for iPhone X
  4. }


To check against iPad, you could probably go:

  1. bool deviceIsIpad = UnityEngine.iOS.Device.generation.ToString().Contains("iPad");
  2. if (deviceIsIpad) {
  3. // Do something for iPad
  4. }


[출처] https://answers.unity.com/questions/1432365/how-to-detect-iphone-x-or-ipad-using-iosdevicegene.html

반응형
Posted by blueasa
, |

유니티에서 아이폰X의 하단 Home Indicator 비활성화 하는 방법 찾다가


유니티는 어느 클래스에 넣으란건지 몰라서 헤멨는데 알맞은 답변을 찾아서 펌~


[추가2]

Unity v5.6.5f1 이상에서 Build Settings에 옵션이 추가 됐는데 하단 소스 대응되는 옵션 스크린샷 추가 해놓음.

1. - (BOOL)prefersHomeIndicatorAutoHidden; // add this

-> Off 돼 있어야 함.


2. - (UIRectEdge)preferredScreenEdgesDeferringSystemGestures; // add this

-> 모두 On


[추가]

아래 소스를 적용해보니 Home Indicator가 Hide 되긴 하는데 아무 곳이나 터치(드래그 아님) 하면 Home Indicator가 활성화 되는 문제가 있어서 다른팀에 문의해보니 prefersHomeIndicatorAutoHidden을 YES로 하면 안된다고 한다.

prefersHomeIndicatorAutoHidden을 소스에서 없애라고 함.

없애고 테스트 해보니 원하는대로 동작(비활성화 상태에서 드래그하면 활성화 되면서 1회 드래그 무시)한다.


[설명]

Unity 5.6.4f1

XCode 9.1


XCode Project-Classes-UI 폴더에 가면 UnityViewControllerBaseiOS.h / UnityViewControllerBaseiOS.mm 파일이 있음.

해당 파일에 아래 add this 주석 달린 소스 추가


[참고]

This is for both status and edge protection


UnityViewControllerBaseiOS.h

Code (CSharp):
  1.  
  2. @interface UnityViewControllerBase : UIViewController
  3. {
  4. }
  5.  
  6. - (BOOL)shouldAutorotate;
  7.  
  8. - (BOOL)prefersStatusBarHidden;
  9. - (UIStatusBarStyle)preferredStatusBarStyle;
  10. - (BOOL)prefersHomeIndicatorAutoHidden; // add this
  11. - (UIRectEdge)preferredScreenEdgesDeferringSystemGestures; // add this
  12. @end
  13.  

UnityViewControllerBaseiOS.mm

Code (CSharp):
  1.  
  2. - (BOOL)shouldAutorotate
  3. {
  4.     return YES;
  5. }
  6.  
  7. // add this
  8. - (BOOL)prefersHomeIndicatorAutoHidden
  9. {
  10.     return YES;
  11. }
  12.  
  13. // add this
  14. - (UIRectEdge)preferredScreenEdgesDeferringSystemGestures
  15. {
  16.     return UIRectEdgeAll;
  17. }
  18.  
  19. - (BOOL)prefersStatusBarHidden
  20. {
  21. ....
  22.  



[출처] https://forum.unity.com/threads/option-to-hide-iphone-x-home-indicator-edge-protection.500991/



반응형
Posted by blueasa
, |

以下はUnity2017.1.1f1Xcode9.0GMで確認しています。

前置き

iPhoneXの対応がめんどくさそう
https://developer.apple.com/ios/human-interface-guidelines/overview/whats-new/

やりたいこと

Unity側でいちいち対応するのは面倒なので、Unityの描画領域を変更して、
iPhoneXの場合は上下に余白を持たせれば良いのでは?という案。

iPhone 8iPhoneX beforeiPhoneX after
iphonex8p.pngiphonex1.pngiphonex2.png

iPhoneX beforeの画像は、iPhone 8の画像と同じコードをそのまま実行したものです。
どう表示されるかはもちろんUnityでの実装によりますが、このサンプルの場合は
画面上部に合わせてテキストを表示しているので、iPhoneXの凹部に隠れてしまっています。

iPhoneX afterの画像は、Unityの描画領域を上50pt、下40pt短くし、余白部分に画像を設定しています。
ついでにステータスバーも表示しています。

ソース

GitHubに上げました。
https://github.com/tkyaji/UnityIPhoneXSupport

UnityIPhoneXSupport.unitypackage をインポートすると、
PostProcessBuildでビルド時にUnityのソースを書き換えて、余白を設定するようになります。

余白のサイズと色、または画像を定数で指定できます。

やってること

1. iPhoneXの場合、ステータスバーを表示する

iPhoneXではステータスバーの非表示は非推奨とのことなので、表示するようにします。

UnityのPlayerSettingsで、Status Ber Hiddenが設定されている場合のみ以下の処理を行います。

  • Info.plistの設定を、ステータスバー表示とする
  • UnityViewControllerBaseiOS.mmを書き換え、iPhoneXの場合は表示、それ以外は非表示とする

2. UnityのViewサイズを変更する

UnityAppController.mmUnityView.mmを書き換え、UIWindowUIViewのサイズをそれぞれ変更します。
高さを90pt短くし、Windowの位置を50pt下げています。
これで上50pt、下40ptの余白ができます。
上下余白部分にUIViewをそれぞれ設定し、色を設定します。
さらに画像がある場合はUIImageViewaddSubViewします。

備考

  • シミュレータで少し確認しただけなので、もしかしたら色々問題があるかもしれません。使用する場合は自己責任でお願いします。
  • iPhoneXのSafe Areaは左右にも余白があるため、ちゃんとやるなら左右にも気を使う必要がありそうです
  • 余白部分がただの黒帯とかだと、そのせいでリジェクトになる可能性があるかもしれません
  • iPhoneXかどうかは画面アスペクト比でざっくり判定しています



[출처] https://qiita.com/tkyaji/items/8cdc0a4324d4e89633e8

반응형
Posted by blueasa
, |