gree / unity-webview

zlib License
2.3k stars 694 forks source link

Clicks not registering in Unity #1115

Open Volko76 opened 5 days ago

Volko76 commented 5 days ago

Hi, I'm trying to make an AR mobile app. The interface is in HTML and is served by a server. It communicates via Unity via EvaluateJS.

I would like to be able to click on the red area to place object in the floor (using a raycast). presentation

The red area is transparent (I set the webview to transparent too) and I see the Unity world here. The issue is that when I click in the red area, my click is not registered by Unity (in android) so it doen't trigger the placement of the object at this position.

I tried to use https://github.com/gree/unity-webview/tree/experimental/unity-over-native-ui and it seems to work in the editor but not in android. I also tried with 32Bit and RendeOverNativeUi enabled and disabled and it changed nothing. I know it is in experimental.

Am I missing something ?

Thanks a lot for the project and the help provided Wishing you the best day

Volko76 commented 5 days ago

I tested on the master branch and I get the same results : it is working in the editor but not on android

KojiNakamaru commented 4 days ago

Transparency doesn't mean that events can be passed to unity. Every event on the webview rectangular region is treated by the webview. The experimental/unity-over-native-ui variant is for drawing unity's elements over webviews. For that variant, you need to specify masks to receive events in unity (cf. https://github.com/gree/unity-webview/pull/584#issuecomment-1761410366 ).

If you utilize the latest one on the master branch, you can receive an event on webview and send it to the unity side by Unity.call().

Volko76 commented 4 days ago

Thanks a lot for the anwser @KojiNakamaru , it clarifies a lot of things.

However, I don't fuly understand how masks are working I think. Can you explain a little bit more how mask are working ?

I forked the experimental branch, enable Render Over UI and 32Bit in the android player settings. Then I allowed cleartext to use my local http server for debug. I set the margins to 0, 0, 0, 0 and the mask to 0, 0, Screen.width, Screen.height to fill the whole screen but I still cannot register a click on a TMP Button.

Am I doing something wrong ?

Thanks a lot

KojiNakamaru commented 3 days ago

I put a modified sample app under https://github.com/gree/unity-webview/tree/example-for-1115/sample where modification commits are below:

https://github.com/gree/unity-webview/compare/4426a65...d8b69d6

In this sample, margins (0, 0, 0, 0) and a mask (0, 0, Screen.width, 100) are specified.

https://github.com/gree/unity-webview/blob/d8b69d66d24b5d79d76ccc23a6f1b3ea21b6ce4f/sample/Assets/Scripts/SampleWebView.cs#L153-L158

We can press top buttons rendered by unity while interacticting the webview in other regions.

Volko76 commented 1 day ago

Thanks a lot for the provided sample app. Unfortunatly, I don't manage to make this sample app to work 😥

This is really strange. I clone this branch, open it up in Unity (6000.0.26f1), opened the sample scene, select android, select developpement build, click on "build and run".

And I can interract with the webview but not with the top buttons.

I'm using a rog phone 6 on android 14. It has 12 Go of ram and a Snapdragon 8+ Gen 1

Volko76 commented 1 day ago

Okay, so I made my experiments and it turns out that in 6000 and in 2022, it does not work but in 2020 it's working. I will try to investigate on why

Volko76 commented 1 day ago

2021 does not work too

Volko76 commented 1 day ago

I tested with 2020.3.48f1 like you, but also with 2020.3.47f1 to see if it was the "reimport" process of Unity that causes issues but they both work.

So the issue surely comes from the changes between 2020 and 2021

Volko76 commented 1 day ago

I tried with iOS and it worked on all versions but not on android

KojiNakamaru commented 13 hours ago

Thanks for testing various unity versions. I investigated what happened and found the following part "bringToBack" logic didn't work for recent unity versions.

https://github.com/gree/unity-webview/blob/d8b69d66d24b5d79d76ccc23a6f1b3ea21b6ce4f/plugins/Android/webview/src/main/java/net/gree/unitywebview/CWebViewPlugin.java#L814-L821

This issue seems unavoidable, so I tweaked event handling logic:

https://github.com/gree/unity-webview/compare/d8b69d6...083dc00

The sample app on the latest https://github.com/gree/unity-webview/tree/example-for-1115 should work correctly. Please note that you need to import the package from this branch as I updated plugin code and binaries only on this branch.

Volko76 commented 6 hours ago

Thanks a lot, I will try it out