Esempio n. 1
0
    void OnGUI()
    {
        if (webView.Hook(this))
        {
            webView.LoadURL(url);
        }

        if (GUI.Button(new Rect(0, 0, 25, 20), "←"))
        {
            webView.Back();
        }
        if (GUI.Button(new Rect(25, 0, 25, 20), "〒"))
        {
            url = "https://google.com";
            webView.LoadURL(url);
        }
        if (GUI.Button(new Rect(50, 0, 25, 20), "→"))
        {
            webView.Forward();
        }

        GUI.SetNextControlName("urlfield");
        url = GUI.TextField(new Rect(75, 0, (position.width / 3) * 2, 20), url);
        var ev = Event.current;

        if (GUI.Button(new Rect(position.width - 75, 0, 75, 20), "Youtube"))
        {
            url = "https://www.youtube.com/";
            webView.LoadURL(url);
        }

        if (ev.isKey && GUI.GetNameOfFocusedControl().Equals("urlfield"))
        {
            if (ev.keyCode == KeyCode.Return)
            {
                webView.LoadURL(url);
                GUIUtility.keyboardControl = 0;
                webView.SetApplicationFocus(true);
                ev.Use();
            }
        }


        if (ev.type == EventType.Repaint)
        {
            webView.OnGUI(new Rect(0, 20, position.width, position.height - 20));
        }
    }
Esempio n. 2
0
    void OnGUI()
    {
        // hook to this window
        if (webView.Hook(this))
        {
            // do the first thing to do
            webView.LoadURL(url);
        }

        // Navigation
        if (GUI.Button(new Rect(0, 0, 25, 20), "←"))
        {
            webView.Back();
        }
        if (GUI.Button(new Rect(25, 0, 25, 20), "→"))
        {
            webView.Forward();
        }

        // URL text field
        GUI.SetNextControlName("urlfield");
        url = GUI.TextField(new Rect(50, 0, position.width - 50, 20), url);
        var ev = Event.current;

        // Focus on web view if return is pressed in URL field
        if (ev.isKey && GUI.GetNameOfFocusedControl().Equals("urlfield"))
        {
            if (ev.keyCode == KeyCode.Return)
            {
                webView.LoadURL(url);
                GUIUtility.keyboardControl = 0;
                webView.SetApplicationFocus(true);
                ev.Use();
            }
        }
        //  else if (ev.keyCode == KeyCode.A && (ev.control | ev.command))


        if (ev.type == EventType.Repaint)
        {
            // keep the browser aware with resize
            webView.OnGUI(new Rect(0, 20, position.width, position.height - 20));
        }
    }