解决输入框无法输入文字需要先在代码中添加以下方法:
void _setUpHardwareKeyboard()
{
// Send keys from the hardware (USB or Bluetooth) keyboard to the webview.
// Use separate `KeyDown()` and `KeyUp()` methods if the webview supports
// it, otherwise just use `IWebView.HandleKeyboardInput()`.
// https://developer.vuplex.com/webview/IWithKeyDownAndUp
_hardwareKeyboardListener = HardwareKeyboardListener.Instantiate();
_hardwareKeyboardListener.KeyDownReceived += (sender, eventArgs) => {
var webViewWithKeyDown = mViewComp.browser.WebView as IWithKeyDownAndUp;
if (webViewWithKeyDown == null)
{
mViewComp.browser.WebView.HandleKeyboardInput(eventArgs.Value);
}
else
{
webViewWithKeyDown.KeyDown(eventArgs.Value, eventArgs.Modifiers);
}
};
_hardwareKeyboardListener.KeyUpReceived += (sender, eventArgs) => {
var webViewWithKeyUp = mViewComp.browser.WebView as IWithKeyDownAndUp;
if (webViewWithKeyUp != null)
{
webViewWithKeyUp.KeyUp(eventArgs.Value, eventArgs.Modifiers);
}
};
}
其中mViewComp.browser就是CanvasWebViewPrefab网页脚本,然后在打开该网页的时候调用下_setUpHardwareKeyboard()方法即可输入文字。
解决输入框无法输入中文需调用方法:
Input.imeCompositionMode = IMECompositionMode.On;
在脚本CanvasWebViewPrefab.cs中330行初始化时添加即可。