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