gree / unity-webview

zlib License
2.25k stars 688 forks source link

Unity webview and photon compatibility? #798

Closed pbgame55 closed 2 years ago

pbgame55 commented 2 years ago

Can this plugin be used with photon? Example scenario : The player sets up a room and 3 other people join this room. When the number of players in the room reaches 4, the scene with the webview plugin loaded is loaded. Webview automatically opens the "google" page. The "masterclient" who created the room can access the webview panel, but the other 3 people cannot access or touch this panel, cannot change the page, cannot type in the search bar, only the masterclient player can access this panel. Other players can only see the panel and see what the masterclient is doing. Is such a scenario possible?

KojiNakamaru commented 2 years ago

For Android/iOS, a webview with this plugin is simply overlayed on unity's rendering view, as many ad solutions do.

cannot type in the search bar

As this plugin doesn't provide any search bar, I guess you realize it with uGUI and it should not have any relation to this plugin. Perhaps your code related to Photon forces each slave client to be a viewer.

pbgame55 commented 2 years ago

Yes you are right, i handled the events i mentioned by accessing the GUI. But I want to ask something. How can I load webViewObject with photon on start() in SampleWebView script file WebViewObject webViewObject; webViewObject = (new GameObject("WebViewObject")).AddComponent<WebViewObject>(); I tried this: webViewObject = PhotonNetwork.Instantiate("WebViewObject", Vector3.zero, Quaternion.identity,0,null); But it doesn't work because I get this error: Type "UnityEngine.GameObject" cannot be implicitly converted to type "WebViewObject" If I define webViewObject as GameObject I don't get error but this time I can't use some functions of webViewObject. For example ( Setmargins, Setvisibility,loadUrl,Init) GameObject webViewObject = PhotonNetwork.Instantiate("WebViewObject", Vector3.zero, Quaternion.identity,0,null);

Would you be helping me in this regard? I want to load WebViewObject with photon because in some cases I want to remove WebViewObject from scene for all player (PhotonNetwork.Destroy(webViewObject))

KojiNakamaru commented 2 years ago

Therefore, you can add WebVieObject in your prefab or add WebViewObject after instantiating a GameObject:

        GameObject go = PhotonNetwork.Instantiate("YourPrefabName", ...);
        WebViewObject wvo = go.AddComponent<WebViewObject>();

Furthermore, there is no need to instantiate WebViewObject as a Component of the GameObject returned by PhotonNetwork.Instantiate(). You can separately instantiate another GameObject for WebViewObject:

        GameObject go1 = PhotonNetwork.Instantiate("YourPrefabName", ...);
        GameObject go2 = new GameObject("WebViewObject");
        WebViewObject wvo = go2.AddComponent<WebViewObject>();
pbgame55 commented 2 years ago

For Android/iOS, a webview with this plugin is simply overlayed on unity's rendering view, as many ad solutions do.

Sorry for reopening this topic and bothering you. I have one last question, if you could help me I would be very, very happy. How can ı implement streaming for the rendered view and share this screen with the others player. Or Webview for other players (non-masterclient) if i wanted to disable interaction scripts and send them which page to show in which position how could i do that? Kind of like remote control. The result should look like this: Webview url is set to "google". When the scene starts, the masterclient can surf on google, but other clients cannot surf, they can only watch the masterclient's screen. Sorry to bother you again.

KojiNakamaru commented 2 years ago

It is difficult to realize such a behavior with this plugin. You should instead utilize other solutions in which webviews are displayed in 3D (i.e., rendered by Unity) and all interactions are performed through Unity's event system. https://assetstore.unity.com/packages/tools/gui/3d-webview-for-android-and-ios-web-browser-135383, for example, seems promising.