File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change
1
+ using UnityEngine ;
2
+
3
+ public class RenderBehindNotchSupport : MonoBehaviour
4
+ {
5
+ public bool RenderBehindNotch = true ;
6
+
7
+ // Constants from https://developer.android.com/reference/android/view/WindowManager.LayoutParams.html
8
+ private const int LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES = 1 ;
9
+ private const int LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER = 2 ;
10
+
11
+ private AndroidJavaObject m_Window ;
12
+ private AndroidJavaObject m_Windowattributes ;
13
+
14
+ void Start ( ) {
15
+ using ( var version = new AndroidJavaClass ( "android.os.Build$VERSION" ) )
16
+ {
17
+ // Supported on Android 9 Pie (API 28) and later
18
+ if ( version . GetStatic < int > ( "SDK_INT" ) < 28 )
19
+ {
20
+ return ;
21
+ }
22
+ }
23
+ using ( var unityPlayer = new AndroidJavaClass ( "com.unity3d.player.UnityPlayer" ) )
24
+ {
25
+ using ( var activity = unityPlayer . GetStatic < AndroidJavaObject > ( "currentActivity" ) )
26
+ {
27
+ m_Window = activity . Call < AndroidJavaObject > ( "getWindow" ) ;
28
+ m_Windowattributes = m_Window . Call < AndroidJavaObject > ( "getAttributes" ) ;
29
+ m_Windowattributes . Set ( "layoutInDisplayCutoutMode" , RenderBehindNotch ?
30
+ LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES :
31
+ LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER ) ;
32
+ activity . Call ( "runOnUiThread" , new AndroidJavaRunnable ( ApplyAttributes ) ) ;
33
+ }
34
+ }
35
+ }
36
+
37
+ void ApplyAttributes ( )
38
+ {
39
+ if ( m_Window != null && m_Windowattributes != null )
40
+ m_Window . Call ( "setAttributes" , m_Windowattributes ) ;
41
+ }
42
+ }
You can’t perform that action at this time.
0 commit comments