WebViewHook icon indicating copy to clipboard operation
WebViewHook copied to clipboard

WebView content disappears when the window is docked

Open dotsquid opened this issue 5 years ago • 4 comments

Despite images in Readme show docked windows with content, in practice when the window is docked its webview content disappears forever (undocking does not return it back). Tested in Unity 2018.4.13 image

dotsquid avatar Dec 07 '19 18:12 dotsquid

I'm experiencing the same issue.

Rickgrendel avatar Mar 13 '20 17:03 Rickgrendel

Yes, I tested this nice code on Unity 2019 and it has an issue when you dock the window. The webview seems to disappear. The problem is that the webview still exists and is fully working, but seems to lose the right position inside the Unity interface, so it is located outside the Editor Window. I tried to resolve this issue by myself, but I don't know how to force the webview to be correctly displayed.

However, this is a possible solution, even if it's not perfect:

In the WebWindow (the Editor), add a bool variable: bool refresh = true;

Then, in the OnGUI() under the if (ev.type == EventType.Repaint), after the webView.OnGUI... add:

BindingFlags fullBinding = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static; MethodInfo isDockedMethod = typeof(EditorWindow).GetProperty("docked", fullBinding).GetGetMethod(true); bool isDocked = (bool)isDockedMethod.Invoke(this, null);

        if (isDocked)
        {
            if (refresh)
            {
                refresh = false;
                DestroyImmediate(webView);
                webView = CreateInstance<WebViewHook>();
                webView.Hook(window);
                webView.LoadURL(url);
                GUIUtility.keyboardControl = 0;
                webView.SetApplicationFocus(true);
            }
        } else
        {
            refresh = true;
        }

Basically, the idea is to recreate the webView when you dock the Editor Window. It's not very nice, but works.

studiostart avatar Nov 06 '20 10:11 studiostart

Wow, thanks @studiostart ! Unfortunately Unity removed WebView from 2020, so now I'm not sure it's reasonable to use it.

dotsquid avatar Nov 06 '20 12:11 dotsquid

Oh, you're right! They removed the webview (and so, also the Asset Store tab) from Unity. What a pity!!!

studiostart avatar Nov 10 '20 13:11 studiostart