Пример #1
0
    async void Start()
    {
        // The CanvasWebViewPrefab's `InitialUrl` property is set via the editor, so it
        // will automatically initialize itself with that URL.
        _canvasWebViewPrefab = GameObject.Find("CanvasWebViewPrefab").GetComponent <CanvasWebViewPrefab>();

        _setUpKeyboard();
        // https://developer.vuplex.com/webview/WebViewPrefab#WaitUntilInitialized
        await _canvasWebViewPrefab.WaitUntilInitialized();

        // Listen for messages from JavaScript.
        // https://developer.vuplex.com/webview/IWebView#MessageEmitted
        // https://support.vuplex.com/articles/how-to-send-messages-from-javascript-to-c-sharp
        _canvasWebViewPrefab.WebView.MessageEmitted += (sender, eventArgs) => {
            var message = eventArgs.Value;
            if (message.StartsWith("auth_success"))
            {
                var authToken = message.Split(new char[] { ':' }, 2)[1];
                Debug.Log("Signin succeeded! Auth token: " + authToken);
            }
            else if (message.StartsWith("auth_skipped"))
            {
                Debug.Log("Signin skipped");
            }
        };
    }
Пример #2
0
    void Start()
    {
        var canvas = GameObject.Find("Canvas");

        // Create a CanvasWebViewPrefab
        // https://developer.vuplex.com/webview/CanvasWebViewPrefab
        _canvasWebViewPrefab = CanvasWebViewPrefab.Instantiate();
        _canvasWebViewPrefab.transform.SetParent(canvas.transform, false);
        _canvasWebViewPrefab.Initialized += (sender, eventArgs) => {
            _canvasWebViewPrefab.WebView.LoadUrl("https://google.com");
        };

        // Create a CanvasKeyboard
        // https://developer.vuplex.com/webview/CanvasKeyboard
        _keyboard = CanvasKeyboard.Instantiate();
        _keyboard.transform.SetParent(canvas.transform, false);
        // Hook up the keyboard so that characters are routed to the CanvasWebViewPrefab.
        _keyboard.InputReceived += (sender, eventArgs) => {
            _canvasWebViewPrefab.WebView.HandleKeyboardInput(eventArgs.Value);
        };

        _positionPrefabs();
    }