diff --git a/dist/package-nofragment/Assets/Plugins/Android/WebViewPlugin.aar b/dist/package-nofragment/Assets/Plugins/Android/WebViewPlugin.aar index 510e617b..582ed731 100644 Binary files a/dist/package-nofragment/Assets/Plugins/Android/WebViewPlugin.aar and b/dist/package-nofragment/Assets/Plugins/Android/WebViewPlugin.aar differ diff --git a/dist/package-nofragment/Assets/Plugins/Editor/UnityWebViewPostprocessBuild.cs b/dist/package-nofragment/Assets/Plugins/Editor/UnityWebViewPostprocessBuild.cs index f5d32144..a9ba9a80 100644 --- a/dist/package-nofragment/Assets/Plugins/Editor/UnityWebViewPostprocessBuild.cs +++ b/dist/package-nofragment/Assets/Plugins/Editor/UnityWebViewPostprocessBuild.cs @@ -76,6 +76,8 @@ public void OnPostGenerateGradleAndroidProject(string basePath) { } } changed = (androidManifest.SetExported(true) || changed); + changed = (androidManifest.SetApplicationTheme("@style/UnityThemeSelector") || changed); + changed = (androidManifest.SetActivityTheme("@style/UnityThemeSelector.Translucent") || changed); changed = (androidManifest.SetWindowSoftInputMode("adjustPan") || changed); changed = (androidManifest.SetHardwareAccelerated(true) || changed); #if UNITYWEBVIEW_ANDROID_USES_CLEARTEXT_TRAFFIC @@ -88,6 +90,9 @@ public void OnPostGenerateGradleAndroidProject(string basePath) { #if UNITYWEBVIEW_ANDROID_ENABLE_MICROPHONE changed = (androidManifest.AddMicrophone() || changed); #endif +//#if UNITY_5_6_0 || UNITY_5_6_1 + changed = (androidManifest.SetActivityName("net.gree.unitywebview.CUnityPlayerActivity") || changed); +//#endif if (changed) { androidManifest.Save(); Debug.Log("unitywebview: adjusted AndroidManifest.xml."); @@ -176,9 +181,9 @@ public static void OnPostprocessBuild(BuildTarget buildTarget, string path) { #if UNITYWEBVIEW_ANDROID_ENABLE_MICROPHONE changed = (androidManifest.AddMicrophone() || changed); #endif -#if UNITY_5_6_0 || UNITY_5_6_1 +//#if UNITY_5_6_0 || UNITY_5_6_1 changed = (androidManifest.SetActivityName("net.gree.unitywebview.CUnityPlayerActivity") || changed); -#endif +//#endif if (changed) { androidManifest.Save(); Debug.LogError("unitywebview: adjusted AndroidManifest.xml. Please rebuild the app."); @@ -240,6 +245,118 @@ public static void OnPostprocessBuild(BuildTarget buildTarget, string path) { dst = (string)method.Invoke(proj, null); } File.WriteAllText(projPath, dst); + + // Classes/UI/UnityView.h + { + var lines0 = File.ReadAllText(path + "/Classes/UI/UnityView.h").Split('\n'); + var lines = new List(); + var phase = 0; + foreach (var line in lines0) { + switch (phase) { + case 0: + lines.Add(line); + if (line.StartsWith("@interface UnityView : UnityRenderingView")) { + phase++; + } + break; + case 1: + lines.Add(line); + if (line.StartsWith("}")) { + phase++; + lines.Add(""); + lines.Add("- (void)clearMasks;"); + lines.Add("- (void)addMask:(CGRect)r;"); + } + break; + default: + lines.Add(line); + break; + } + } + File.WriteAllText(path + "/Classes/UI/UnityView.h", string.Join("\n", lines)); + } + // Classes/UI/UnityView.mm + { + var lines0 = File.ReadAllText(path + "/Classes/UI/UnityView.mm").Split('\n'); + var lines = new List(); + var phase = 0; + foreach (var line in lines0) { + switch (phase) { + case 0: + lines.Add(line); + if (line.StartsWith("@implementation UnityView")) { + phase++; + } + break; + case 1: + if (line.StartsWith("}")) { + phase++; + lines.Add(" NSMutableArray *_masks;"); + lines.Add(line); + lines.Add(@" +- (void)clearMasks +{ + if (_masks == nil) { + _masks = [[NSMutableArray alloc] init]; + } + [_masks removeAllObjects]; +} + +- (void)addMask:(CGRect)r +{ + if (_masks == nil) { + _masks = [[NSMutableArray alloc] init]; + } + [_masks addObject:[NSValue valueWithCGRect:r]]; +} + +- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event +{ + //CGRect mask = CGRectMake(0, 0, 1334, 100); + //return CGRectContainsPoint(mask, point); + for (NSValue *v in _masks) { + if (CGRectContainsPoint([v CGRectValue], point)) { + return TRUE; + } + } + return FALSE; +} +"); + } else { + lines.Add(line); + } + break; + default: + lines.Add(line); + break; + } + } + lines.Add(@" +extern ""C"" { + UIView *UnityGetGLView(); + void CWebViewPlugin_ClearMasks(); + void CWebViewPlugin_AddMask(int x, int y, int w, int h); +} + +void CWebViewPlugin_ClearMasks() +{ + [(UnityView *)UnityGetGLView() clearMasks]; +} + +void CWebViewPlugin_AddMask(int x, int y, int w, int h) +{ + UIView *view = UnityGetGLViewController().view; + CGFloat scale = 1.0f; + if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) { + scale = view.window.screen.nativeScale; + } else { + scale = view.contentScaleFactor; + } + [(UnityView *)UnityGetGLView() addMask:CGRectMake(x / scale, y / scale, w / scale, h / scale)]; +} +"); + File.WriteAllText(path + "/Classes/UI/UnityView.mm", string.Join("\n", lines)); + } } } } @@ -316,6 +433,25 @@ internal bool SetExported(bool enabled) { return changed; } + internal bool SetApplicationTheme(string theme) { + bool changed = false; + if (ApplicationElement.GetAttribute("theme", AndroidXmlNamespace) != theme) { + ApplicationElement.SetAttribute("theme", AndroidXmlNamespace, theme); + changed = true; + } + return changed; + } + + internal bool SetActivityTheme(string theme) { + bool changed = false; + var activity = GetActivityWithLaunchIntent() as XmlElement; + if (activity.GetAttribute("theme", AndroidXmlNamespace) != theme) { + activity.SetAttribute("theme", AndroidXmlNamespace, theme); + changed = true; + } + return changed; + } + internal bool SetWindowSoftInputMode(string mode) { bool changed = false; var activity = GetActivityWithLaunchIntent() as XmlElement; diff --git a/dist/package-nofragment/Assets/Plugins/WebViewObject.cs b/dist/package-nofragment/Assets/Plugins/WebViewObject.cs index 842a454b..58a57f9b 100644 --- a/dist/package-nofragment/Assets/Plugins/WebViewObject.cs +++ b/dist/package-nofragment/Assets/Plugins/WebViewObject.cs @@ -494,6 +494,10 @@ private static extern void _CWebViewPlugin_Reload( [DllImport("WebView")] private static extern string _CWebViewPlugin_GetMessage(IntPtr instance); #elif UNITY_IPHONE + [DllImport("__Internal")] + private static extern void CWebViewPlugin_ClearMasks(); + [DllImport("__Internal")] + private static extern void CWebViewPlugin_AddMask(int x, int y, int w, int h); [DllImport("__Internal")] private static extern IntPtr _CWebViewPlugin_Init(string gameObject, bool transparent, bool zoom, string ua, bool enableWKWebView, int wkContentMode, bool wkAllowsLinkPreview, bool wkAllowsBackForwardNavigationGestures, int radius); [DllImport("__Internal")] @@ -590,6 +594,32 @@ public static bool IsWebViewAvailable() #endif } + public static void ClearMasks() + { +#if !UNITY_EDITOR && UNITY_ANDROID + using(AndroidJavaClass UnityClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer")) + { + var activity = UnityClass.GetStatic("currentActivity"); + activity.Call("clearMasks"); + } +#elif !UNITY_EDITOR && UNITY_IPHONE + CWebViewPlugin_ClearMasks(); +#endif + } + + public static void AddMask(int x, int y, int w, int h) + { +#if !UNITY_EDITOR && UNITY_ANDROID + using(AndroidJavaClass UnityClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer")) + { + var activity = UnityClass.GetStatic("currentActivity"); + activity.Call("addMask", x, y, w, h); + } +#elif !UNITY_EDITOR && UNITY_IPHONE + CWebViewPlugin_AddMask(x, y, w, h); +#endif + } + public void Init( Callback cb = null, Callback err = null, diff --git a/dist/package-nofragment/Assets/Plugins/iOS/WebView.mm b/dist/package-nofragment/Assets/Plugins/iOS/WebView.mm index 0d720044..bdb34e0d 100644 --- a/dist/package-nofragment/Assets/Plugins/iOS/WebView.mm +++ b/dist/package-nofragment/Assets/Plugins/iOS/WebView.mm @@ -260,7 +260,7 @@ - (id)initWithGameObjectName:(const char *)gameObjectName_ transparent:(BOOL)tra [webView addObserver:self forKeyPath: @"loading" options: NSKeyValueObservingOptionNew context:nil]; - [view addSubview:webView]; + [view.superview insertSubview:webView atIndex:0]; return self; } diff --git a/dist/package-nofragment/Assets/Plugins/iOS/WebViewWithUIWebView.mm b/dist/package-nofragment/Assets/Plugins/iOS/WebViewWithUIWebView.mm index 57b7f300..a8fe6086 100644 --- a/dist/package-nofragment/Assets/Plugins/iOS/WebViewWithUIWebView.mm +++ b/dist/package-nofragment/Assets/Plugins/iOS/WebViewWithUIWebView.mm @@ -320,7 +320,7 @@ - (id)initWithGameObjectName:(const char *)gameObjectName_ transparent:(BOOL)tra [webView addObserver:self forKeyPath: @"loading" options: NSKeyValueObservingOptionNew context:nil]; - [view addSubview:webView]; + [view.superview insertSubview:webView atIndex:0]; return self; } diff --git a/dist/package/Assets/Plugins/Android/WebViewPlugin.aar b/dist/package/Assets/Plugins/Android/WebViewPlugin.aar index a882e5c9..3df7b459 100644 Binary files a/dist/package/Assets/Plugins/Android/WebViewPlugin.aar and b/dist/package/Assets/Plugins/Android/WebViewPlugin.aar differ diff --git a/dist/package/Assets/Plugins/Editor/UnityWebViewPostprocessBuild.cs b/dist/package/Assets/Plugins/Editor/UnityWebViewPostprocessBuild.cs index e3e606fd..a6db0a35 100644 --- a/dist/package/Assets/Plugins/Editor/UnityWebViewPostprocessBuild.cs +++ b/dist/package/Assets/Plugins/Editor/UnityWebViewPostprocessBuild.cs @@ -76,6 +76,8 @@ public void OnPostGenerateGradleAndroidProject(string basePath) { } } changed = (androidManifest.SetExported(true) || changed); + changed = (androidManifest.SetApplicationTheme("@style/UnityThemeSelector") || changed); + changed = (androidManifest.SetActivityTheme("@style/UnityThemeSelector.Translucent") || changed); changed = (androidManifest.SetWindowSoftInputMode("adjustPan") || changed); changed = (androidManifest.SetHardwareAccelerated(true) || changed); #if UNITYWEBVIEW_ANDROID_USES_CLEARTEXT_TRAFFIC @@ -88,6 +90,9 @@ public void OnPostGenerateGradleAndroidProject(string basePath) { #if UNITYWEBVIEW_ANDROID_ENABLE_MICROPHONE changed = (androidManifest.AddMicrophone() || changed); #endif +//#if UNITY_5_6_0 || UNITY_5_6_1 + changed = (androidManifest.SetActivityName("net.gree.unitywebview.CUnityPlayerActivity") || changed); +//#endif if (changed) { androidManifest.Save(); Debug.Log("unitywebview: adjusted AndroidManifest.xml."); @@ -176,9 +181,9 @@ public static void OnPostprocessBuild(BuildTarget buildTarget, string path) { #if UNITYWEBVIEW_ANDROID_ENABLE_MICROPHONE changed = (androidManifest.AddMicrophone() || changed); #endif -#if UNITY_5_6_0 || UNITY_5_6_1 +//#if UNITY_5_6_0 || UNITY_5_6_1 changed = (androidManifest.SetActivityName("net.gree.unitywebview.CUnityPlayerActivity") || changed); -#endif +//#endif if (changed) { androidManifest.Save(); Debug.LogError("unitywebview: adjusted AndroidManifest.xml. Please rebuild the app."); @@ -240,6 +245,118 @@ public static void OnPostprocessBuild(BuildTarget buildTarget, string path) { dst = (string)method.Invoke(proj, null); } File.WriteAllText(projPath, dst); + + // Classes/UI/UnityView.h + { + var lines0 = File.ReadAllText(path + "/Classes/UI/UnityView.h").Split('\n'); + var lines = new List(); + var phase = 0; + foreach (var line in lines0) { + switch (phase) { + case 0: + lines.Add(line); + if (line.StartsWith("@interface UnityView : UnityRenderingView")) { + phase++; + } + break; + case 1: + lines.Add(line); + if (line.StartsWith("}")) { + phase++; + lines.Add(""); + lines.Add("- (void)clearMasks;"); + lines.Add("- (void)addMask:(CGRect)r;"); + } + break; + default: + lines.Add(line); + break; + } + } + File.WriteAllText(path + "/Classes/UI/UnityView.h", string.Join("\n", lines)); + } + // Classes/UI/UnityView.mm + { + var lines0 = File.ReadAllText(path + "/Classes/UI/UnityView.mm").Split('\n'); + var lines = new List(); + var phase = 0; + foreach (var line in lines0) { + switch (phase) { + case 0: + lines.Add(line); + if (line.StartsWith("@implementation UnityView")) { + phase++; + } + break; + case 1: + if (line.StartsWith("}")) { + phase++; + lines.Add(" NSMutableArray *_masks;"); + lines.Add(line); + lines.Add(@" +- (void)clearMasks +{ + if (_masks == nil) { + _masks = [[NSMutableArray alloc] init]; + } + [_masks removeAllObjects]; +} + +- (void)addMask:(CGRect)r +{ + if (_masks == nil) { + _masks = [[NSMutableArray alloc] init]; + } + [_masks addObject:[NSValue valueWithCGRect:r]]; +} + +- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event +{ + //CGRect mask = CGRectMake(0, 0, 1334, 100); + //return CGRectContainsPoint(mask, point); + for (NSValue *v in _masks) { + if (CGRectContainsPoint([v CGRectValue], point)) { + return TRUE; + } + } + return FALSE; +} +"); + } else { + lines.Add(line); + } + break; + default: + lines.Add(line); + break; + } + } + lines.Add(@" +extern ""C"" { + UIView *UnityGetGLView(); + void CWebViewPlugin_ClearMasks(); + void CWebViewPlugin_AddMask(int x, int y, int w, int h); +} + +void CWebViewPlugin_ClearMasks() +{ + [(UnityView *)UnityGetGLView() clearMasks]; +} + +void CWebViewPlugin_AddMask(int x, int y, int w, int h) +{ + UIView *view = UnityGetGLViewController().view; + CGFloat scale = 1.0f; + if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) { + scale = view.window.screen.nativeScale; + } else { + scale = view.contentScaleFactor; + } + [(UnityView *)UnityGetGLView() addMask:CGRectMake(x / scale, y / scale, w / scale, h / scale)]; +} +"); + File.WriteAllText(path + "/Classes/UI/UnityView.mm", string.Join("\n", lines)); + } } } } @@ -316,6 +433,25 @@ internal bool SetExported(bool enabled) { return changed; } + internal bool SetApplicationTheme(string theme) { + bool changed = false; + if (ApplicationElement.GetAttribute("theme", AndroidXmlNamespace) != theme) { + ApplicationElement.SetAttribute("theme", AndroidXmlNamespace, theme); + changed = true; + } + return changed; + } + + internal bool SetActivityTheme(string theme) { + bool changed = false; + var activity = GetActivityWithLaunchIntent() as XmlElement; + if (activity.GetAttribute("theme", AndroidXmlNamespace) != theme) { + activity.SetAttribute("theme", AndroidXmlNamespace, theme); + changed = true; + } + return changed; + } + internal bool SetWindowSoftInputMode(string mode) { bool changed = false; var activity = GetActivityWithLaunchIntent() as XmlElement; diff --git a/dist/package/Assets/Plugins/WebViewObject.cs b/dist/package/Assets/Plugins/WebViewObject.cs index 842a454b..58a57f9b 100644 --- a/dist/package/Assets/Plugins/WebViewObject.cs +++ b/dist/package/Assets/Plugins/WebViewObject.cs @@ -494,6 +494,10 @@ private static extern void _CWebViewPlugin_Reload( [DllImport("WebView")] private static extern string _CWebViewPlugin_GetMessage(IntPtr instance); #elif UNITY_IPHONE + [DllImport("__Internal")] + private static extern void CWebViewPlugin_ClearMasks(); + [DllImport("__Internal")] + private static extern void CWebViewPlugin_AddMask(int x, int y, int w, int h); [DllImport("__Internal")] private static extern IntPtr _CWebViewPlugin_Init(string gameObject, bool transparent, bool zoom, string ua, bool enableWKWebView, int wkContentMode, bool wkAllowsLinkPreview, bool wkAllowsBackForwardNavigationGestures, int radius); [DllImport("__Internal")] @@ -590,6 +594,32 @@ public static bool IsWebViewAvailable() #endif } + public static void ClearMasks() + { +#if !UNITY_EDITOR && UNITY_ANDROID + using(AndroidJavaClass UnityClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer")) + { + var activity = UnityClass.GetStatic("currentActivity"); + activity.Call("clearMasks"); + } +#elif !UNITY_EDITOR && UNITY_IPHONE + CWebViewPlugin_ClearMasks(); +#endif + } + + public static void AddMask(int x, int y, int w, int h) + { +#if !UNITY_EDITOR && UNITY_ANDROID + using(AndroidJavaClass UnityClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer")) + { + var activity = UnityClass.GetStatic("currentActivity"); + activity.Call("addMask", x, y, w, h); + } +#elif !UNITY_EDITOR && UNITY_IPHONE + CWebViewPlugin_AddMask(x, y, w, h); +#endif + } + public void Init( Callback cb = null, Callback err = null, diff --git a/dist/package/Assets/Plugins/iOS/WebView.mm b/dist/package/Assets/Plugins/iOS/WebView.mm index 0d720044..bdb34e0d 100644 --- a/dist/package/Assets/Plugins/iOS/WebView.mm +++ b/dist/package/Assets/Plugins/iOS/WebView.mm @@ -260,7 +260,7 @@ - (id)initWithGameObjectName:(const char *)gameObjectName_ transparent:(BOOL)tra [webView addObserver:self forKeyPath: @"loading" options: NSKeyValueObservingOptionNew context:nil]; - [view addSubview:webView]; + [view.superview insertSubview:webView atIndex:0]; return self; } diff --git a/dist/package/Assets/Plugins/iOS/WebViewWithUIWebView.mm b/dist/package/Assets/Plugins/iOS/WebViewWithUIWebView.mm index 57b7f300..a8fe6086 100644 --- a/dist/package/Assets/Plugins/iOS/WebViewWithUIWebView.mm +++ b/dist/package/Assets/Plugins/iOS/WebViewWithUIWebView.mm @@ -320,7 +320,7 @@ - (id)initWithGameObjectName:(const char *)gameObjectName_ transparent:(BOOL)tra [webView addObserver:self forKeyPath: @"loading" options: NSKeyValueObservingOptionNew context:nil]; - [view addSubview:webView]; + [view.superview insertSubview:webView atIndex:0]; return self; } diff --git a/dist/unity-webview-nofragment.unitypackage b/dist/unity-webview-nofragment.unitypackage index d25b0847..6d50b9b5 100644 Binary files a/dist/unity-webview-nofragment.unitypackage and b/dist/unity-webview-nofragment.unitypackage differ diff --git a/dist/unity-webview-nofragment.zip b/dist/unity-webview-nofragment.zip index 3b7ab37c..8c545c2f 100644 Binary files a/dist/unity-webview-nofragment.zip and b/dist/unity-webview-nofragment.zip differ diff --git a/dist/unity-webview.unitypackage b/dist/unity-webview.unitypackage index 9ab9a55a..affdafa5 100644 Binary files a/dist/unity-webview.unitypackage and b/dist/unity-webview.unitypackage differ diff --git a/dist/unity-webview.zip b/dist/unity-webview.zip index 4825bf73..73608331 100644 Binary files a/dist/unity-webview.zip and b/dist/unity-webview.zip differ