@@ -93,6 +93,8 @@ public void OnPostGenerateGradleAndroidProject(string basePath) {
9393 }
9494 }
9595 changed = ( androidManifest . SetExported ( true ) || changed ) ;
96+ changed = ( androidManifest . SetApplicationTheme ( "@style/UnityThemeSelector" ) || changed ) ;
97+ changed = ( androidManifest . SetActivityTheme ( "@style/UnityThemeSelector.Translucent" ) || changed ) ;
9698 changed = ( androidManifest . SetWindowSoftInputMode ( "adjustPan" ) || changed ) ;
9799 changed = ( androidManifest . SetHardwareAccelerated ( true ) || changed ) ;
98100#if UNITYWEBVIEW_ANDROID_USES_CLEARTEXT_TRAFFIC
@@ -105,6 +107,9 @@ public void OnPostGenerateGradleAndroidProject(string basePath) {
105107#if UNITYWEBVIEW_ANDROID_ENABLE_MICROPHONE
106108 changed = ( androidManifest . AddMicrophone ( ) || changed ) ;
107109#endif
110+ //#if UNITY_5_6_0 || UNITY_5_6_1
111+ changed = ( androidManifest . SetActivityName ( "net.gree.unitywebview.CUnityPlayerActivity" ) || changed ) ;
112+ //#endif
108113 if ( changed ) {
109114 androidManifest . Save ( ) ;
110115 Debug . Log ( "unitywebview: adjusted AndroidManifest.xml." ) ;
@@ -205,9 +210,9 @@ public static void OnPostprocessBuild(BuildTarget buildTarget, string path) {
205210#if UNITYWEBVIEW_ANDROID_ENABLE_MICROPHONE
206211 changed = ( androidManifest . AddMicrophone ( ) || changed ) ;
207212#endif
208- #if UNITY_5_6_0 || UNITY_5_6_1
213+ // #if UNITY_5_6_0 || UNITY_5_6_1
209214 changed = ( androidManifest . SetActivityName ( "net.gree.unitywebview.CUnityPlayerActivity" ) || changed ) ;
210- #endif
215+ // #endif
211216 if ( changed ) {
212217 androidManifest . Save ( ) ;
213218 Debug . LogError ( "unitywebview: adjusted AndroidManifest.xml and/or WebView.aar. Please rebuild the app." ) ;
@@ -269,6 +274,132 @@ public static void OnPostprocessBuild(BuildTarget buildTarget, string path) {
269274 dst = ( string ) method . Invoke ( proj , null ) ;
270275 }
271276 File . WriteAllText ( projPath , dst ) ;
277+
278+ // Classes/UI/UnityAppController+ViewHandling.mm
279+ {
280+ var text = File . ReadAllText ( path + "/Classes/UI/UnityAppController+ViewHandling.mm" ) ;
281+ text = text . Replace (
282+ @"
283+ _rootController.view = _rootView = _unityView;
284+ " ,
285+ @"
286+ UIView *view = [[UIView alloc] initWithFrame:controller.view.bounds];
287+ [view addSubview:_unityView];
288+ _rootController.view = _rootView = view;
289+ " ) ;
290+ File . WriteAllText ( path + "/Classes/UI/UnityAppController+ViewHandling.mm" , text ) ;
291+ }
292+ // Classes/UI/UnityView.h
293+ {
294+ var lines0 = File . ReadAllText ( path + "/Classes/UI/UnityView.h" ) . Split ( '\n ' ) ;
295+ var lines = new List < string > ( ) ;
296+ var phase = 0 ;
297+ foreach ( var line in lines0 ) {
298+ switch ( phase ) {
299+ case 0 :
300+ lines . Add ( line ) ;
301+ if ( line . StartsWith ( "@interface UnityView : UnityRenderingView" ) ) {
302+ phase ++ ;
303+ }
304+ break ;
305+ case 1 :
306+ lines . Add ( line ) ;
307+ if ( line . StartsWith ( "}" ) ) {
308+ phase ++ ;
309+ lines . Add ( "" ) ;
310+ lines . Add ( "- (void)clearMasks;" ) ;
311+ lines . Add ( "- (void)addMask:(CGRect)r;" ) ;
312+ }
313+ break ;
314+ default :
315+ lines . Add ( line ) ;
316+ break ;
317+ }
318+ }
319+ File . WriteAllText ( path + "/Classes/UI/UnityView.h" , string . Join ( "\n " , lines ) ) ;
320+ }
321+ // Classes/UI/UnityView.mm
322+ {
323+ var lines0 = File . ReadAllText ( path + "/Classes/UI/UnityView.mm" ) . Split ( '\n ' ) ;
324+ var lines = new List < string > ( ) ;
325+ var phase = 0 ;
326+ foreach ( var line in lines0 ) {
327+ switch ( phase ) {
328+ case 0 :
329+ lines . Add ( line ) ;
330+ if ( line . StartsWith ( "@implementation UnityView" ) ) {
331+ phase ++ ;
332+ }
333+ break ;
334+ case 1 :
335+ if ( line . StartsWith ( "}" ) ) {
336+ phase ++ ;
337+ lines . Add ( " NSMutableArray<NSValue *> *_masks;" ) ;
338+ lines . Add ( line ) ;
339+ lines . Add ( @"
340+ - (void)clearMasks
341+ {
342+ if (_masks == nil) {
343+ _masks = [[NSMutableArray<NSValue *> alloc] init];
344+ }
345+ [_masks removeAllObjects];
346+ }
347+
348+ - (void)addMask:(CGRect)r
349+ {
350+ if (_masks == nil) {
351+ _masks = [[NSMutableArray<NSValue *> alloc] init];
352+ }
353+ [_masks addObject:[NSValue valueWithCGRect:r]];
354+ }
355+
356+ - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
357+ {
358+ //CGRect mask = CGRectMake(0, 0, 1334, 100);
359+ //return CGRectContainsPoint(mask, point);
360+ for (NSValue *v in _masks) {
361+ if (CGRectContainsPoint([v CGRectValue], point)) {
362+ return TRUE;
363+ }
364+ }
365+ return FALSE;
366+ }
367+ " ) ;
368+ } else {
369+ lines . Add ( line ) ;
370+ }
371+ break ;
372+ default :
373+ lines . Add ( line ) ;
374+ break ;
375+ }
376+ }
377+ lines . Add ( @"
378+ extern ""C"" {
379+ UIView *UnityGetGLView();
380+ void CWebViewPlugin_ClearMasks();
381+ void CWebViewPlugin_AddMask(int x, int y, int w, int h);
382+ }
383+
384+ void CWebViewPlugin_ClearMasks()
385+ {
386+ [(UnityView *)UnityGetGLView() clearMasks];
387+ }
388+
389+ void CWebViewPlugin_AddMask(int x, int y, int w, int h)
390+ {
391+ UIView *view = UnityGetGLViewController().view;
392+ CGFloat scale = 1.0f;
393+ if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
394+ scale = view.window.screen.nativeScale;
395+ } else {
396+ scale = view.contentScaleFactor;
397+ }
398+ [(UnityView *)UnityGetGLView() addMask:CGRectMake(x / scale, y / scale, w / scale, h / scale)];
399+ }
400+ " ) ;
401+ File . WriteAllText ( path + "/Classes/UI/UnityView.mm" , string . Join ( "\n " , lines ) ) ;
402+ }
272403 }
273404 }
274405}
@@ -345,6 +476,25 @@ internal bool SetExported(bool enabled) {
345476 return changed ;
346477 }
347478
479+ internal bool SetApplicationTheme ( string theme ) {
480+ bool changed = false ;
481+ if ( ApplicationElement . GetAttribute ( "theme" , AndroidXmlNamespace ) != theme ) {
482+ ApplicationElement . SetAttribute ( "theme" , AndroidXmlNamespace , theme ) ;
483+ changed = true ;
484+ }
485+ return changed ;
486+ }
487+
488+ internal bool SetActivityTheme ( string theme ) {
489+ bool changed = false ;
490+ var activity = GetActivityWithLaunchIntent ( ) as XmlElement ;
491+ if ( activity . GetAttribute ( "theme" , AndroidXmlNamespace ) != theme ) {
492+ activity . SetAttribute ( "theme" , AndroidXmlNamespace , theme ) ;
493+ changed = true ;
494+ }
495+ return changed ;
496+ }
497+
348498 internal bool SetWindowSoftInputMode ( string mode ) {
349499 bool changed = false ;
350500 var activity = GetActivityWithLaunchIntent ( ) as XmlElement ;
0 commit comments