The project is a module that brings the native mobile keyboard to TMP_InputField in Unity WebGL builds. Out of the box, Unity WebGL does not open the phone keyboard properly, so I made my own solution: the MobileWebGLKeyboardTools class, which works together with the web-gl-mobile-keyboard.jslib plugin
It supports emoji (text can be replaced with <sprite=Index> images), closing the keyboard after submit and full styling of the input field through CSS values
- Add the module to your project (the
Runtimefolder with theWebGLMobileKeyboardModuleassembly) - Put
web-gl-mobile-keyboard.jslibfrom theWebGLfolder of this repository intoAssets/Plugins/WebGL
If the default look suits you and you don't want to initialize the input field from code, just add the InputFieldMobileWebGLKeyboardInitializer component to the GameObject with the input field
Call the method below on start for every input field that should open the mobile keyboard (each one is initialized separately):
#if UNITY_WEBGL && !UNITY_EDITOR
_inputField.InitializeInputFieldForMobileKeyboard(
shouldReplaceEmojiTextToImage: true,
shouldCloseKeyboardAfterSubmit: true,
fontSize: "18px");
#endifWrap the call in #if UNITY_WEBGL && !UNITY_EDITOR: calling an extern method in the Editor throws an error
inputField- the input field the keyboard is opened forshouldReplaceEmojiTextToImage- whether to replace text with images (emoji). If not,<sprite=Index>stays plain textshouldCloseKeyboardAfterSubmit- whether to close the keyboard after pressing submitcolor- text color of the input field
Input field settings take CSS values. If you're not sure what to pass, look up CSS examples online:
backgroundColor- background colortop- offset from the top edge of the screenbottom- offset from the bottom edge of the screenleft- offset from the left edge of the screenwidth- widthheight- heighttransform- offset of the element relative to itselfposition- position modeborder- borderfontSize- font size (at least16pxis recommended)
Any parameter you leave out falls back to its default:
Happy to hear any feedback or questions! :)