@@ -37,49 +37,51 @@ public static void createPlayer(final Activity activity, final UnityPlayerCallba
37
37
callback .onReady ();
38
38
return ;
39
39
}
40
- activity .runOnUiThread (new Runnable () {
41
- @ Override
42
- public void run () {
43
- activity .getWindow ().setFormat (PixelFormat .RGBA_8888 );
44
- int flag = activity .getWindow ().getAttributes ().flags ;
45
- boolean fullScreen = false ;
46
- if ((flag & WindowManager .LayoutParams .FLAG_FULLSCREEN ) == WindowManager .LayoutParams .FLAG_FULLSCREEN ) {
47
- fullScreen = true ;
48
- }
49
-
50
- unityPlayer = new UnityPlayer (activity , new IUnityPlayerLifecycleEvents () {
51
- @ Override
52
- public void onUnityPlayerUnloaded () {
53
- callback .onUnload ();
40
+ if (activity != null ) {
41
+ activity .runOnUiThread (new Runnable () {
42
+ @ Override
43
+ public void run () {
44
+ activity .getWindow ().setFormat (PixelFormat .RGBA_8888 );
45
+ int flag = activity .getWindow ().getAttributes ().flags ;
46
+ boolean fullScreen = false ;
47
+ if ((flag & WindowManager .LayoutParams .FLAG_FULLSCREEN ) == WindowManager .LayoutParams .FLAG_FULLSCREEN ) {
48
+ fullScreen = true ;
54
49
}
55
50
56
- @ Override
57
- public void onUnityPlayerQuitted () {
58
- callback .onQuit ();
51
+ unityPlayer = new UnityPlayer (activity , new IUnityPlayerLifecycleEvents () {
52
+ @ Override
53
+ public void onUnityPlayerUnloaded () {
54
+ callback .onUnload ();
55
+ }
56
+
57
+ @ Override
58
+ public void onUnityPlayerQuitted () {
59
+ callback .onQuit ();
60
+ }
61
+ });
62
+
63
+ try {
64
+ // wait a moment. fix unity cannot start when startup.
65
+ Thread .sleep (1000 );
66
+ } catch (Exception e ) {
59
67
}
60
- });
61
-
62
- try {
63
- // wait a moment. fix unity cannot start when startup.
64
- Thread .sleep (1000 );
65
- } catch (Exception e ) {
66
- }
67
68
68
- // start unity
69
- addUnityViewToBackground ();
70
- unityPlayer .windowFocusChanged (true );
71
- unityPlayer .requestFocus ();
72
- unityPlayer .resume ();
69
+ // start unity
70
+ addUnityViewToBackground ();
71
+ unityPlayer .windowFocusChanged (true );
72
+ unityPlayer .requestFocus ();
73
+ unityPlayer .resume ();
73
74
74
- // restore window layout
75
- if (!fullScreen ) {
76
- activity .getWindow ().addFlags (WindowManager .LayoutParams .FLAG_FORCE_NOT_FULLSCREEN );
77
- activity .getWindow ().clearFlags (WindowManager .LayoutParams .FLAG_FULLSCREEN );
75
+ // restore window layout
76
+ if (!fullScreen ) {
77
+ activity .getWindow ().addFlags (WindowManager .LayoutParams .FLAG_FORCE_NOT_FULLSCREEN );
78
+ activity .getWindow ().clearFlags (WindowManager .LayoutParams .FLAG_FULLSCREEN );
79
+ }
80
+ _isUnityReady = true ;
81
+ callback .onReady ();
78
82
}
79
- _isUnityReady = true ;
80
- callback .onReady ();
81
- }
82
- });
83
+ });
84
+ }
83
85
}
84
86
85
87
public static void pause () {
0 commit comments