Skip to main content

VirtualKeyboard

A class in Root.Township, the global namespace.

In-world VR keyboard that builds keys from a VirtualKeyboardSetup, optionally bent around an axis, and keeps the typed text. Client side.

Constructors​

MemberWhat it is
VirtualKeyboard()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

13 private and internal fields
MemberWhat it is
private Vector3 bendingAxisAxis the keyboard curves around when bendingRadius is positive.
private Vector3 bendingNormalDirection the keyboard faces, used when bending the key layout.
private float bendingRadiusRadius of the keyboard's curve. Zero or less (the default is -1) keeps the keys flat.
private float doubleShiftTimerSeconds within which a second shift press locks shift (default 0.5).
private string inputBacking field for Input, the text typed so far.
private bool isShiftLockedTrue when shift is locked by a double press, so it stays on after typing a character.
private Transform keyParentTransform the spawned keys are parented to.
private VirtualKey keyPrefabThe VirtualKey prefab spawned for each key.
private Vector2 originOffsetOffset added to every key's layout position after scaling.
private float scaleMultiplier applied to the key layout positions.
private VirtualKeyboardSetup setupThe VirtualKeyboardSetup asset that lists the keys and their layout positions.
private GameObject shiftLockMarkerObject meant to show that shift lock is on. Not used in this class's code.
private float timeToDoubleShiftReal time until which a second shift press counts as a double press.

Properties​

MemberWhat it is
string Input { get; set; }The typed text. Setting it raises InputChanged and releases shift unless shift is locked.
bool IsShiftPressed { get; private set; }True while shift is active.
bool IsShowingSecret { get; private set; }Whether secret text is shown in plain.

Events​

MemberWhat it is
event Action<bool> DisplaySecretToggledRaised when secret (password) display is toggled.
event Action InputChangedRaised when the text changes.
event Action NextPressedRaised when return is pressed.
event Action<bool> ShiftChangedRaised when shift turns on or off.

Methods​

MemberWhat it is
void ClearFocus()Removes every InputChanged and NextPressed listener, so the previous field stops receiving input.
void KeyPressed(KeyCode key)Handles a key: letters, digits, symbols, backspace, space, return (raises NextPressed) and shift.
void ToggleSecret(bool isShowingSecret)Sets whether secret text is shown and raises DisplaySecretToggled.
6 private and internal methods
MemberWhat it is
private void GetPosition(Vector2 original, out Vector3 position, out Quaternion rotation)Turns a key's 2D layout position into a local position and rotation, applying scale, originOffset and the optional bend.
private void IncludeLetter(string letter)Appends a letter to Input, upper case if shift is down and lower case otherwise.
private void IncludeNumber(int number)Appends a digit to Input.
private void OnDrawGizmos()Editor only: draws a wire box at each key position from setup while not playing.
private void PressShift()Toggles shift. A second press within doubleShiftTimer seconds turns on shift lock instead.
private void Start()Spawns one keyPrefab per entry in setup under keyParent and places each one.

Used in​

Members of other types that take, return or hold a VirtualKeyboard: