Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webview behind UI #503

Open
frederikw03 opened this issue Jan 29, 2020 · 18 comments
Open

Webview behind UI #503

frederikw03 opened this issue Jan 29, 2020 · 18 comments

Comments

@frederikw03
Copy link

Is there an easy way to get the webview behind some UI in my scene?
image

i want it to be in the white space

@KojiNakamaru
Copy link
Member

Unfortunately you cannot overlay any unity-native UI element, as a native webview is placed over unity's rendering view. (cf. #471, for example).

@frederikw03
Copy link
Author

is there any way to render he webview on a Unity ui element?

@Chriztophaa
Copy link

In Unity 2019.2 there is in project settings => player => Resolution and Presentation the checkbox for "Render over nativeUI". This works for me on iOS and Android.

@KojiNakamaru
Copy link
Member

@Chriztophaa Thanks!

@dstivens
Copy link

@Chriztophaa Hello, I hope you can help me. To explain what i did, I made a new project, added a sprite and then added the SampleWebView script to an empty object to get the webview running. Changing the "Render over nativeUI" didn't change anything, the webview works fine but the sprite is always below it. Am i missing something?

@KojiNakamaru
Copy link
Member

Hmm, I tried by myself and with small tweaks for WebView.mm (I only tested the iOS version) a webview was shown behind unity's UI rendering. However, events such as for clicking/dragging didn't be passed to the webview as discussed in https://stackoverflow.com/questions/56018894/android-ios-pass-clicks-on-unityplayer-to-underlying-layout-views . I would also like to know if there is any simple way to solve these issues.

@Chriztophaa
Copy link

Hey,

I had the same issue. I found the following workaround:

=> change in WebView.mm => do not add the webview, instead insert it at position 0 so that it is placed under the unity view.

=> then you need to extend the unity view and override the following method:
https://developer.apple.com/documentation/uikit/uiview/1622533-pointinside
If you return NO at a specific point then the click will not be processed by the unity view and will be routed to the underlying webview.

@KojiNakamaru
Copy link
Member

https://developer.apple.com/documentation/uikit/uiview/1622533-pointinside

If we handle events adequately by this method, we need to somehow perform the check for non-rectangle regions, for overlapped buttons such as in #503 (comment). We could first capture the whole screen and generate a mask, which is then passed to the extended unity view to check wheter an event location is inside the webview region. Theoretically possible, but complicated... Anyway, thank you:-).

@DaWiHs
Copy link

DaWiHs commented Aug 7, 2020

Hello, I'm trying to get that WebView being rendered behind the Unity's UI. I've checked the 'Render over NativeUI' and nothing changed. I've found these WebView.mm (2 files) but have no clue what to edit there to make it work. May I get some directions?

@KojiNakamaru
Copy link
Member

With the following tweak, a webview will be placed behind the unity's view.

diff --git a/plugins/iOS/WebView.mm b/plugins/iOS/WebView.mm
index e01751d..f147b7a 100644
--- a/plugins/iOS/WebView.mm
+++ b/plugins/iOS/WebView.mm
@@ -160,7 +160,7 @@ static NSMutableArray *_instances = [[NSMutableArray alloc] init];
 
     [webView addObserver:self forKeyPath: @"loading" options: NSKeyValueObservingOptionNew context:nil];
 
-    [view addSubview:webView];
+    [view.superview insertSubview:webView atIndex:0];
 
     return self;
 }

@DaWiHs
Copy link

DaWiHs commented Aug 13, 2020

Changed it but apparently it (well ofc, it's under iOS plugins) doesn't do for Android.
Unity 2019.3.14f1, Android 10

@dstivens
Copy link

i had to add another manifest into "Assets\Plugins\Android":
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"> <uses-permission android:name="android.permission.INTERNET"/> <application> <activity android:name="com.unity3d.player.UnityPlayerActivity" android:windowSoftInputMode="stateHidden" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>

@DaWiHs
Copy link

DaWiHs commented Aug 13, 2020

Okay, I think that did the trick.
It did the trick so hard that I can't see the WebView at all.
Unity's UI elements does not cover entire screen, only about 1/5th of it from the bottom, WebView margins are 0, 5, 0, 50.
Camera 'Clear Flags' set to 'Depth only' bc I thought the skybox renders over it but it doesn't do too.
The WebView clearly renders bc when closing app I can see loaded page for just milliseconds. Any ideas?

@dstivens
Copy link

i have the camera background set to a solid colour and the colour needs to have 0 for the alpha channel. You also need to have "Render over native UI" set in the android player settings under Resolution and presentation settings.

@DaWiHs
Copy link

DaWiHs commented Aug 13, 2020

Render over native UI was already set to true. Solid color doesn't work too...
117636126_308844333902645_4000658046924321640_n
image

@KojiNakamaru
Copy link
Member

I investigated further and uploaded an experimental implementation #584. If you are still interested in, could you please have a try.

@UnityDev9999
Copy link

Will this work on the unity editor as well?

@KojiNakamaru
Copy link
Member

@UnityDev524 No, it doesn't work on Unity Editor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants