@@ -76,6 +76,8 @@ public void OnPostGenerateGradleAndroidProject(string basePath) {
76
76
}
77
77
}
78
78
changed = ( androidManifest . SetExported ( true ) || changed ) ;
79
+ changed = ( androidManifest . SetApplicationTheme ( "@style/UnityThemeSelector" ) || changed ) ;
80
+ changed = ( androidManifest . SetActivityTheme ( "@style/UnityThemeSelector.Translucent" ) || changed ) ;
79
81
changed = ( androidManifest . SetWindowSoftInputMode ( "adjustPan" ) || changed ) ;
80
82
changed = ( androidManifest . SetHardwareAccelerated ( true ) || changed ) ;
81
83
#if UNITYWEBVIEW_ANDROID_USES_CLEARTEXT_TRAFFIC
@@ -88,6 +90,9 @@ public void OnPostGenerateGradleAndroidProject(string basePath) {
88
90
#if UNITYWEBVIEW_ANDROID_ENABLE_MICROPHONE
89
91
changed = ( androidManifest . AddMicrophone ( ) || changed ) ;
90
92
#endif
93
+ //#if UNITY_5_6_0 || UNITY_5_6_1
94
+ changed = ( androidManifest . SetActivityName ( "net.gree.unitywebview.CUnityPlayerActivity" ) || changed ) ;
95
+ //#endif
91
96
if ( changed ) {
92
97
androidManifest . Save ( ) ;
93
98
Debug . Log ( "unitywebview: adjusted AndroidManifest.xml." ) ;
@@ -176,9 +181,9 @@ public static void OnPostprocessBuild(BuildTarget buildTarget, string path) {
176
181
#if UNITYWEBVIEW_ANDROID_ENABLE_MICROPHONE
177
182
changed = ( androidManifest . AddMicrophone ( ) || changed ) ;
178
183
#endif
179
- #if UNITY_5_6_0 || UNITY_5_6_1
184
+ // #if UNITY_5_6_0 || UNITY_5_6_1
180
185
changed = ( androidManifest . SetActivityName ( "net.gree.unitywebview.CUnityPlayerActivity" ) || changed ) ;
181
- #endif
186
+ // #endif
182
187
if ( changed ) {
183
188
androidManifest . Save ( ) ;
184
189
Debug . LogError ( "unitywebview: adjusted AndroidManifest.xml. Please rebuild the app." ) ;
@@ -240,6 +245,118 @@ public static void OnPostprocessBuild(BuildTarget buildTarget, string path) {
240
245
dst = ( string ) method . Invoke ( proj , null ) ;
241
246
}
242
247
File . WriteAllText ( projPath , dst ) ;
248
+
249
+ // Classes/UI/UnityView.h
250
+ {
251
+ var lines0 = File . ReadAllText ( path + "/Classes/UI/UnityView.h" ) . Split ( '\n ' ) ;
252
+ var lines = new List < string > ( ) ;
253
+ var phase = 0 ;
254
+ foreach ( var line in lines0 ) {
255
+ switch ( phase ) {
256
+ case 0 :
257
+ lines . Add ( line ) ;
258
+ if ( line . StartsWith ( "@interface UnityView : UnityRenderingView" ) ) {
259
+ phase ++ ;
260
+ }
261
+ break ;
262
+ case 1 :
263
+ lines . Add ( line ) ;
264
+ if ( line . StartsWith ( "}" ) ) {
265
+ phase ++ ;
266
+ lines . Add ( "" ) ;
267
+ lines . Add ( "- (void)clearMasks;" ) ;
268
+ lines . Add ( "- (void)addMask:(CGRect)r;" ) ;
269
+ }
270
+ break ;
271
+ default :
272
+ lines . Add ( line ) ;
273
+ break ;
274
+ }
275
+ }
276
+ File . WriteAllText ( path + "/Classes/UI/UnityView.h" , string . Join ( "\n " , lines ) ) ;
277
+ }
278
+ // Classes/UI/UnityView.mm
279
+ {
280
+ var lines0 = File . ReadAllText ( path + "/Classes/UI/UnityView.mm" ) . Split ( '\n ' ) ;
281
+ var lines = new List < string > ( ) ;
282
+ var phase = 0 ;
283
+ foreach ( var line in lines0 ) {
284
+ switch ( phase ) {
285
+ case 0 :
286
+ lines . Add ( line ) ;
287
+ if ( line . StartsWith ( "@implementation UnityView" ) ) {
288
+ phase ++ ;
289
+ }
290
+ break ;
291
+ case 1 :
292
+ if ( line . StartsWith ( "}" ) ) {
293
+ phase ++ ;
294
+ lines . Add ( " NSMutableArray<NSValue *> *_masks;" ) ;
295
+ lines . Add ( line ) ;
296
+ lines . Add ( @"
297
+ - (void)clearMasks
298
+ {
299
+ if (_masks == nil) {
300
+ _masks = [[NSMutableArray<NSValue *> alloc] init];
301
+ }
302
+ [_masks removeAllObjects];
303
+ }
304
+
305
+ - (void)addMask:(CGRect)r
306
+ {
307
+ if (_masks == nil) {
308
+ _masks = [[NSMutableArray<NSValue *> alloc] init];
309
+ }
310
+ [_masks addObject:[NSValue valueWithCGRect:r]];
311
+ }
312
+
313
+ - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
314
+ {
315
+ //CGRect mask = CGRectMake(0, 0, 1334, 100);
316
+ //return CGRectContainsPoint(mask, point);
317
+ for (NSValue *v in _masks) {
318
+ if (CGRectContainsPoint([v CGRectValue], point)) {
319
+ return TRUE;
320
+ }
321
+ }
322
+ return FALSE;
323
+ }
324
+ " ) ;
325
+ } else {
326
+ lines . Add ( line ) ;
327
+ }
328
+ break ;
329
+ default :
330
+ lines . Add ( line ) ;
331
+ break ;
332
+ }
333
+ }
334
+ lines . Add ( @"
335
+ extern ""C"" {
336
+ UIView *UnityGetGLView();
337
+ void CWebViewPlugin_ClearMasks();
338
+ void CWebViewPlugin_AddMask(int x, int y, int w, int h);
339
+ }
340
+
341
+ void CWebViewPlugin_ClearMasks()
342
+ {
343
+ [(UnityView *)UnityGetGLView() clearMasks];
344
+ }
345
+
346
+ void CWebViewPlugin_AddMask(int x, int y, int w, int h)
347
+ {
348
+ UIView *view = UnityGetGLViewController().view;
349
+ CGFloat scale = 1.0f;
350
+ if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
351
+ scale = view.window.screen.nativeScale;
352
+ } else {
353
+ scale = view.contentScaleFactor;
354
+ }
355
+ [(UnityView *)UnityGetGLView() addMask:CGRectMake(x / scale, y / scale, w / scale, h / scale)];
356
+ }
357
+ " ) ;
358
+ File . WriteAllText ( path + "/Classes/UI/UnityView.mm" , string . Join ( "\n " , lines ) ) ;
359
+ }
243
360
}
244
361
}
245
362
}
@@ -316,6 +433,25 @@ internal bool SetExported(bool enabled) {
316
433
return changed ;
317
434
}
318
435
436
+ internal bool SetApplicationTheme ( string theme ) {
437
+ bool changed = false ;
438
+ if ( ApplicationElement . GetAttribute ( "theme" , AndroidXmlNamespace ) != theme ) {
439
+ ApplicationElement . SetAttribute ( "theme" , AndroidXmlNamespace , theme ) ;
440
+ changed = true ;
441
+ }
442
+ return changed ;
443
+ }
444
+
445
+ internal bool SetActivityTheme ( string theme ) {
446
+ bool changed = false ;
447
+ var activity = GetActivityWithLaunchIntent ( ) as XmlElement ;
448
+ if ( activity . GetAttribute ( "theme" , AndroidXmlNamespace ) != theme ) {
449
+ activity . SetAttribute ( "theme" , AndroidXmlNamespace , theme ) ;
450
+ changed = true ;
451
+ }
452
+ return changed ;
453
+ }
454
+
319
455
internal bool SetWindowSoftInputMode ( string mode ) {
320
456
bool changed = false ;
321
457
var activity = GetActivityWithLaunchIntent ( ) as XmlElement ;
0 commit comments