@@ -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,133 @@ 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.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
288+ [view addSubview:_unityView];
289+ _rootController.view = _rootView = view;
290+ " ) ;
291+ File . WriteAllText ( path + "/Classes/UI/UnityAppController+ViewHandling.mm" , text ) ;
292+ }
293+ // Classes/UI/UnityView.h
294+ {
295+ var lines0 = File . ReadAllText ( path + "/Classes/UI/UnityView.h" ) . Split ( '\n ' ) ;
296+ var lines = new List < string > ( ) ;
297+ var phase = 0 ;
298+ foreach ( var line in lines0 ) {
299+ switch ( phase ) {
300+ case 0 :
301+ lines . Add ( line ) ;
302+ if ( line . StartsWith ( "@interface UnityView : UnityRenderingView" ) ) {
303+ phase ++ ;
304+ }
305+ break ;
306+ case 1 :
307+ lines . Add ( line ) ;
308+ if ( line . StartsWith ( "}" ) ) {
309+ phase ++ ;
310+ lines . Add ( "" ) ;
311+ lines . Add ( "- (void)clearMasks;" ) ;
312+ lines . Add ( "- (void)addMask:(CGRect)r;" ) ;
313+ }
314+ break ;
315+ default :
316+ lines . Add ( line ) ;
317+ break ;
318+ }
319+ }
320+ File . WriteAllText ( path + "/Classes/UI/UnityView.h" , string . Join ( "\n " , lines ) ) ;
321+ }
322+ // Classes/UI/UnityView.mm
323+ {
324+ var lines0 = File . ReadAllText ( path + "/Classes/UI/UnityView.mm" ) . Split ( '\n ' ) ;
325+ var lines = new List < string > ( ) ;
326+ var phase = 0 ;
327+ foreach ( var line in lines0 ) {
328+ switch ( phase ) {
329+ case 0 :
330+ lines . Add ( line ) ;
331+ if ( line . StartsWith ( "@implementation UnityView" ) ) {
332+ phase ++ ;
333+ }
334+ break ;
335+ case 1 :
336+ if ( line . StartsWith ( "}" ) ) {
337+ phase ++ ;
338+ lines . Add ( " NSMutableArray<NSValue *> *_masks;" ) ;
339+ lines . Add ( line ) ;
340+ lines . Add ( @"
341+ - (void)clearMasks
342+ {
343+ if (_masks == nil) {
344+ _masks = [[NSMutableArray<NSValue *> alloc] init];
345+ }
346+ [_masks removeAllObjects];
347+ }
348+
349+ - (void)addMask:(CGRect)r
350+ {
351+ if (_masks == nil) {
352+ _masks = [[NSMutableArray<NSValue *> alloc] init];
353+ }
354+ [_masks addObject:[NSValue valueWithCGRect:r]];
355+ }
356+
357+ - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
358+ {
359+ //CGRect mask = CGRectMake(0, 0, 1334, 100);
360+ //return CGRectContainsPoint(mask, point);
361+ for (NSValue *v in _masks) {
362+ if (CGRectContainsPoint([v CGRectValue], point)) {
363+ return TRUE;
364+ }
365+ }
366+ return FALSE;
367+ }
368+ " ) ;
369+ } else {
370+ lines . Add ( line ) ;
371+ }
372+ break ;
373+ default :
374+ lines . Add ( line ) ;
375+ break ;
376+ }
377+ }
378+ lines . Add ( @"
379+ extern ""C"" {
380+ UIView *UnityGetGLView();
381+ void CWebViewPlugin_ClearMasks();
382+ void CWebViewPlugin_AddMask(int x, int y, int w, int h);
383+ }
384+
385+ void CWebViewPlugin_ClearMasks()
386+ {
387+ [(UnityView *)UnityGetGLView() clearMasks];
388+ }
389+
390+ void CWebViewPlugin_AddMask(int x, int y, int w, int h)
391+ {
392+ UIView *view = UnityGetGLViewController().view;
393+ CGFloat scale = 1.0f;
394+ if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
395+ scale = view.window.screen.nativeScale;
396+ } else {
397+ scale = view.contentScaleFactor;
398+ }
399+ [(UnityView *)UnityGetGLView() addMask:CGRectMake(x / scale, y / scale, w / scale, h / scale)];
400+ }
401+ " ) ;
402+ File . WriteAllText ( path + "/Classes/UI/UnityView.mm" , string . Join ( "\n " , lines ) ) ;
403+ }
272404 }
273405 }
274406}
@@ -345,6 +477,25 @@ internal bool SetExported(bool enabled) {
345477 return changed ;
346478 }
347479
480+ internal bool SetApplicationTheme ( string theme ) {
481+ bool changed = false ;
482+ if ( ApplicationElement . GetAttribute ( "theme" , AndroidXmlNamespace ) != theme ) {
483+ ApplicationElement . SetAttribute ( "theme" , AndroidXmlNamespace , theme ) ;
484+ changed = true ;
485+ }
486+ return changed ;
487+ }
488+
489+ internal bool SetActivityTheme ( string theme ) {
490+ bool changed = false ;
491+ var activity = GetActivityWithLaunchIntent ( ) as XmlElement ;
492+ if ( activity . GetAttribute ( "theme" , AndroidXmlNamespace ) != theme ) {
493+ activity . SetAttribute ( "theme" , AndroidXmlNamespace , theme ) ;
494+ changed = true ;
495+ }
496+ return changed ;
497+ }
498+
348499 internal bool SetWindowSoftInputMode ( string mode ) {
349500 bool changed = false ;
350501 var activity = GetActivityWithLaunchIntent ( ) as XmlElement ;
0 commit comments