3D WebView 插件的一些小记录

解决二次打开网页,还是在上次滑动的位置,没有回到顶点的原因:

lianJie_ZiXun.transform.GetChild(index).GetComponent<CanvasWebViewPrefab>().WebView.ExecuteJavaScript("window.scrollTo(0, 0);");

输入中文查询:

 public CanvasWebViewPrefab canvasWebViewPrefab;
    public CanvasKeyboard canvasKeyboard;
     HardwareKeyboardListener _hardwareKeyboardListener;
    private EventSystem _eventSystem;
    // Start is called before the first frame update
    void Start()
    {
        //_eventSystem = EventSystem.current;

        
        inputField.onEndEdit.AddListener((text) =>
        {
            canvasWebViewPrefab.WebView.SendKey("document.activeElement.value = '" + text + "'");
        });
        canvasWebViewPrefab.InitialUrl = "http://123.232.102.30:59994/college/tutorList.html";

        // Async_等待web初始化并打开网址(ST_数组_网址[0]);

        Async_判断是否聚焦在输入框内来显隐键盘();

        Async_网页键盘给输入框传输字符();
    }


    async void Async_判断是否聚焦在输入框内来显隐键盘()
    {
        await canvasKeyboard.WaitUntilInitialized();
        canvasKeyboard.gameObject.SetActive(false);

        await canvasWebViewPrefab.WaitUntilInitialized();
        canvasWebViewPrefab.WebView.FocusedInputFieldChanged += (sender, eventArgs) =>
        {
            var shouldShowKeyboard = eventArgs.Type != FocusedInputFieldType.None;
            //canvasKeyboard.gameObject.SetActive(shouldShowKeyboard);
            inputField.gameObject.SetActive(true);
            //inputField.ActivateInputField(true);
            keyboard = Process.Start("C:\\Windows\\System32\\osk.exe");
            inputField.Select();
            //_eventSystem.SetSelectedGameObject(inputField.gameObject, new BaseEventDate(_eventSystem));
        };

    }

    async void Async_网页键盘给输入框传输字符()
    {

        await canvasWebViewPrefab.WaitUntilInitialized();
        var webViewWithKeyDownAndUp = canvasWebViewPrefab.WebView as IWithKeyDownAndUp;
        _hardwareKeyboardListener = HardwareKeyboardListener.Instantiate();
        _hardwareKeyboardListener.KeyDownReceived += (sender, eventArgs) => {
            if (webViewWithKeyDownAndUp != null)
            {
                webViewWithKeyDownAndUp.KeyDown(eventArgs.Value, eventArgs.Modifiers);
            }
            else
            {
                canvasWebViewPrefab.WebView.SendKey(eventArgs.Value);
            }
        };
        _hardwareKeyboardListener.KeyUpReceived += (sender, eventArgs) => {
            webViewWithKeyDownAndUp?.KeyUp(eventArgs.Value, eventArgs.Modifiers);
        };
        canvasKeyboard.InputReceived += (sender, eventArgs) => {
            canvasWebViewPrefab.WebView.SendKey(eventArgs.Value);
        };
    }

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

rain_love_snow

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值