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

카테고리

분류 전체보기 (2342)N
Unity3D (577)
Programming (473)
Unreal (4)
Gamebryo (56)
Tip & Tech (187)N
협업 (34)
3DS Max (3)
Game (12)
Utility (116)
Etc (92)
Link (31)
Portfolio (19)
Subject (90)
iOS,OSX (38)
Android (13)
Linux (5)
잉여 프로젝트 (2)
게임이야기 (1)
Memories (20)
Interest (37)
Thinking (36)
한글 (26)
PaperCraft (5)
Animation (408)
Wallpaper (2)
재테크 (19)
Exercise (3)
나만의 맛집 (2)
냥이 (9)
육아 (13)
Total1,356,249
Today17
Yesterday269
Statistics Graph

달력

« » 2020.1
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31  

공지사항

태그목록

 

[링크] https://github.com/Over17/UnityAndroidNotchSupport

 

Over17/UnityAndroidNotchSupport

Support for Android Notch (Cutout) in Unity 2017.4 and earlier - Over17/UnityAndroidNotchSupport

github.com

UnityAndroidNotchSupport

Android devices with a notch (display cutout) have recently become quite common. However, if you make a Unity application and deploy it to such device, by default Android OS will letter-box your app so that it the notch doesn't interfere with your UI.

If you want to make use of the whole display surface area and render in the area "behind" the notch, you need to add code to your application. Fortunately, since Unity 2018.3 there is a special option in the Player settings called "Render outside safe area" which does exactly this. If you want to have the same option in earlier versions of Unity - this plugin was made for you!

One advantage of this plugin over the built-in Unity solution is that it allows changing the setting in runtime if needed, by calling public void SetRenderBehindNotch(bool enabled) in RenderBehindNotchSupport.

If you are planning to make use of "rendering behind the notch" feature, you'll also need another feature which returns you the area of the screen which is outside of the notch area (and is safe to render to). The API is equivalent to what Screen.safeArea API does in newer Unity versions, and returns a Rect.

This plugin is targeted towards Unity 2017.4, however I see no reasons why it shouldn't work with earlier versions too.

System Requirements

  • Tested on Unity 2017.4.28f1. Should work on any Unity version out there, but make sure your target API is set to 28 or higher. There is no point in using this plugin in Unity 2018.3 or later because these versions have notch support out of the box.
  • An Android device with Android 9 Pie or later. Some devices with earlier Android versions have notch/cutout, but Google has added a corresponding API only in Android 9. Feel free to add other vendor-specific bits of code to add support on earlier Androids at your own risk.

Usage

  1. Copy the contents of Assets directory to your project
  2. Attach the Assets/Scripts/RenderBehindNotchSupport.cs script to a game object of your choice in your first scene to make sure the plugin is loaded as early as possible
  3. The script has a public boolean property so that you can tick/untick the checkbox to enable or disable rendering behind the notch with a single click
  4. If you want to change the setting in runtime, call public void SetRenderBehindNotch(bool enabled) in RenderBehindNotchSupport class.
  5. Attach the Assets/Scripts/AndroidSafeArea.cs script to a game object of your choice if you need the safe area API. The property AndroidSafeArea.safeArea is returning a Rect, use it to layout your UI.
  6. Enjoy

Alternative solution

Instead of using the script (or if you want to apply the "render behind the notch" flag as early as possible), you could modify the theme used by Unity. To do so, please create a file at the path Assets/Plugins/Android/res/values-v28/styles.xml with the following contents:

Unity 2017.4 or newer

<?xml version="1.0" encoding="utf-8"?> <resources> <style name="BaseUnityTheme" parent="android:Theme.Material.Light.NoActionBar.Fullscreen"> <item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item> </style> </resources>

Before 2017.4 (ie. 5.6)

<?xml version="1.0" encoding="utf-8"?> <resources> <style name="UnityThemeSelector" parent="android:Theme.Material.Light.NoActionBar.Fullscreen"> <item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item> </style> </resources>

There is no need to add the script to your project in this case. You may also need to tweak the snippet above if you are using a custom theme.

I recommend using the default approach with the script unless you have good reasons to do otherwise.

Useful Links

License

Licensed under MIT license.

Posted by blueasa

댓글을 달아 주세요