gree / unity-webview

zlib License
2.31k stars 695 forks source link

Webviewer displays blank #896

Open Conundroy opened 1 year ago

Conundroy commented 1 year ago

I added WebViewObject.cs and a custom webview manager to a game object, however it only displays a solid dark gray. Here's my webview manager script. Tested on my Android 12 device:

using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class WebViewManager : MonoBehaviour
{
    public string Url = "https://google.com";
    public WebViewObject webViewObject;

    IEnumerator Start()
    {
        int screenWidth = Screen.width;
        int screenHeight = Screen.height;
        webViewObject.Init((msg) =>
        {
            Debug.Log($"CallFromJS[{msg}]");
        });

        webViewObject.SetMargins(screenWidth / 4, screenHeight / 4, screenWidth / 4, screenHeight / 4);
        webViewObject.SetVisibility(true);

#if !UNITY_WEBPLAYER && !UNITY_WEBGL
        webViewObject.LoadURL(Url.Replace(" ", "%20"));
#else
        webViewObject.LoadURL("StreamingAssets/" + Url.Replace(" ", "%20"));
#endif

        yield break;
    }
}
KojiNakamaru commented 1 year ago

Did you create a WebViewObject component and set it to webViewObject correctly? I tried to use your WebViewManager in the sample app and it run on both Android 11 and Android 12 devices.

Conundroy commented 1 year ago

Did you create a WebViewObject component and set it to webViewObject correctly? I tried to use your WebViewManager in the sample app and it run on both Android 11 and Android 12 devices.

I have, here's how they're set up: image

KojiNakamaru commented 1 year ago

I've put a modified sample app with WebViewManager, which can be directly opened with 2020.3.45f1. Please check it.

https://github.com/gree/unity-webview/tree/example-for-896/sample