Skip to main content

TouchScreenKeyboardKey

A class in Root.Township, the global namespace.

One key on the in-game VR touch screen keyboard. Shows its label (changing with shift), sends its key to the TouchScreenKeyboard when pressed, and repeats backspace when held. Client only.

Constructors​

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

Fields​

MemberWhat it is
Vector2 spaceButtonSizeTouch size used for the space bar.
25 private and internal fields
MemberWhat it is
private float backspaceDelayTime left before the held backspace moves to its next stage.
private TouchScreenKeyboardKey.KeySizeType buttonTypeSize class of the key (normal, suggestion or space bar), set from the key code.
private List<UnityEvent> changesEvents to run when this key is pressed, from onPressChange.
private float closestDistanceSquared distance of the nearest finger this frame.
private float closestDistanceToPressSquaredSquared distance under which the key starts moving towards the finger.
private TextRenderer completionTextLabel used for word suggestion keys.
private float continuousBackspaceDelayTime until the next repeated backspace.
private TouchScreenKeyboardKey.BackspaceActions currentActionStage of a held backspace: single, continuous or word.
private Vector3 depressedPositionLocal position of the key cap when no finger is close.
private Transform distancePositionTransform moved in and out as a finger gets near.
private Transform distanceScalingTransform scaled by finger distance when scaleWithDistanceOn is set. Key images are also spawned under it.
private bool isUsingSpecialSetupNot used in this build.
private TouchScreenKeyboardKey.SpecialKeySetup[] onPressChangePer key code, events to invoke each time that key is pressed.
private Material pressMaterialMaterial shown while pressed.
private Renderer pressRendererRenderer whose material swaps on press and release.
private Material releasedMaterialMaterial shown when released.
private bool scaleWithDistanceOnScales the key by finger distance when true.
private AnimationCurve scaleWithDistanceSquaredCurve from squared finger distance to key scale.
private TouchScreenKeyboardKey.SpecialKeySetup[] specialSetupsPer key code, events run once at setup to change that key's look.
private Vector2 suggestionButtonSizeButton size for suggestion keys (F5 to F8).
private TextRenderer textMain key label.
private float touchDistanceTouch depth of the nearest finger, used with touchDistanceToPress.
private AnimationCurve touchDistanceToPressCurve from touch depth to how far the key cap moves.
private IUnityUpdateMethod updateBackspaceRegistered update method for held backspace.
private TouchScreenKeyboard virtualKeyboardThe keyboard this key belongs to.

Properties​

MemberWhat it is
override Vector2 ButtonSize { get; }Touch size of the key: the base size, the suggestion size, or the space bar size.
2 private and internal properties
MemberWhat it is
private VirtualKeyInfo Info { get; set; }Key codes (normal and shifted) this key sends.
private TextRenderer Text { get; }The label in use: the main text, or the completion text when the main one is hidden.

Events​

MemberWhat it is
event Action<bool> ShiftChangedShift change event declared on the key. Nothing in this class raises it.

Methods​

MemberWhat it is
void ApplyText(string newText)Sets the key's label, if it differs from the current one.
void ClearDistance()Resets the closest finger distance before a new round of UpdateDistance calls.
TouchScreenKeyboardKey.KeySizeType GetButtonTypeFromKeyCode(KeyCode keycode, out Vector2 size)Size type for a key code: Space is the space bar, F5 to F8 are suggestion keys, everything else is a base key.
string GetText()The key's current label.
void InitShowingSecret(GameObject hideObject)Hides the given object unless the keyboard's current user shows secret (password) text.
void Setup(VirtualKeyInfo info, TouchScreenKeyboard virtualKeyboard, bool? scaleWithDistance = null)Sets the key's layout info and keyboard, applies any special setup for that key, and otherwise labels it and follows shift changes.
void SetupDistance()Applies the closest finger distance: scales the key if enabled and pushes it in when a finger is close enough.
void UpdateDistance(float distanceSquared, float touchDistance)Records a finger distance if it is closer than any seen since ClearDistance.
protected override void InternalPress()Sends the key (or its shift key) to the keyboard, starts the backspace repeat for backspace, and runs any on-press events.
protected override void InternalRelease()Restores the released material and stops the backspace repeat.
5 private and internal methods
MemberWhat it is
private bool CheckForSpecialSetup(VirtualKeyInfo info)Applies mapped function-key visuals and special setups for this key, and collects its on-press events. True if any applied.
private void OnDestroy()Unhooks from the keyboard's shift change and stops the backspace update.
private void SetupCoreReferences(TouchScreenKeyboard virtualKeyboard, bool? scaleWithDistance)Stores the keyboard, picks the key size from the key code and optionally overrides distance scaling.
private void UpdateBackspace()Per-frame while backspace is held: one delete, then repeated deletes, then whole-word deletes.
private void UpdateImage(bool isShiftPressed)Sets the label to the character for the current key, upper or lower case by shift.

Used in​

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