Quickstart

Sample Scenes

The package provides two sample scenes in the Samples/Scenes folder that demonstrate the Keybaord.

Both scenes require additional packages or package samples:

SampleScene - XR Controller

  • Starter Assets (XR Interaction Toolkit)

SampleScene - XR Controller and Hands

  • XR Hands

  • Hands Interaction Demo (XR Interaction Toolkit)

Attention

Be aware that as of XR Interaction Toolkit v3.5, VR interactions with UI Toolkit in the editor only work if the Game View has active focus. Bringing the Game View into focus can be done by simply clicking anywhere inside the Game View window. https://docs.unity3d.com/Packages/com.unity.xr.interaction.toolkit@3.5/manual/ui-world-space-ui-toolkit-support.html#known-limitations

Integrating in Your Scene

You can use the prefabs in the Prefabs folder to add the Keyboard to your scene.

Simply drag and drop the GlobalKeyboard prefab into your scene. It acts as a global Keyboard for all inputs.

Note

To use the XR Interaction Toolkit with UI Toolkit, you need to set up your scene accordingly. You can use the World Space UI Support prefab, which already includes the required components, or follow the official instructions here to do it manually: https://docs.unity3d.com/Packages/com.unity.xr.interaction.toolkit@3.2/manual/ui-world-space-ui-toolkit-support.html

Bind to Inputs

To open the Keyboard when an input is pressed, you need to bind the input to the Keyboard. This works differently wether you use UI Toolkit or uGUI.

UI Toolkit

This is an example script that you can attach to your UI Document that searches all TextFields and opens the Keyboard on focus:

public class UIToolkitExample : MonoBehaviour
{
    void Start()
    {
        if (TryGetComponent(out UIDocument document))
        {
            document.rootVisualElement.Query<TextField>().ForEach(textField =>
            {
                GlobalKeyboard.Instance.Keyboard.Bind(textField, () =>
                {
                    GlobalKeyboard.Instance.Keyboard.transform.position = Camera.main.transform.position + Camera.main.transform.forward * 0.5f;
                });
            });
        }
    }
}

Unity uGUI

For uGUI you can do something similar with a script that is attached to the parent canvas:

public class UGUIExample : MonoBehaviour
{
    void Start()
    {
        foreach (TMP_InputField textField in GetComponentsInChildren<TMP_InputField>())
        {
            GlobalKeyboard.Instance.Keyboard.Bind(textField, () =>
            {
                GlobalKeyboard.Instance.Keyboard.transform.position = Camera.main.transform.position + Camera.main.transform.forward * 0.5f;
            });
        }
    }
}