TouchScreenKeyboard
A class in Root.Township, the global namespace.
The in-world virtual keyboard players type on with their fingers. Client only; one shared instance, moved into place with Get for whichever text field (IUseVirtualKeyboard) is using it.
- Listed in Global namespace: T to X
- Inherits or implements
TouchScreenMenuBase - Nested types
KeyBoardEdgesInfo,OutputEvent
Constructors
| Member | What it is |
|---|---|
TouchScreenKeyboard() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
| Member | What it is |
|---|---|
bool setupSecretKey | If set, an extra secret toggle key is added to the last row. |
27 private and internal fields
| Member | What it is |
|---|---|
private KeyboardSet androidMultiKeyboardSetup | Android keyboard set. Not used in this build, see MultiKeyboardSetup. |
private VirtualKeyboardSetup androidSetup | Android single layout. Not read in this build. |
private AutoComplete autoComplete | The autocomplete helper, made by ApplyNewAutoCompletionSource. |
private float backspaceDelayStart | Backing field for BackspaceDelayStart. Default 1. |
private float backspaceSingleLetterDuration | Backing field for BackspaceSingleLetterDuration. Default 3. |
private float continuousBackspaceSpeed | Backing field for ContinuousBackspaceSpeed. Default 0.2. |
private int currentKeyboardIndex | Index of the layout in use within the keyboard set. |
private Vector2 dimensionsOffset | Centre offset of the touch area, recomputed by ResetDimensions. |
private float doubleShiftTimer | Seconds within which a second shift press locks shift. Default 0.5. |
private const string empty | Empty string constant. |
private FunctionKeyDefinition[] functionKeys | Keys with their own actions; mapped into MappedFunctionKeys in Awake. |
private bool hasDoneAutoCompleteSetup | True once AutoCompleteSetup has run. |
private readonly Dictionary<int, KeyCode> indexToKeyCode | Maps suggestion slot 0 to 3 to key codes F5 to F8. |
private string input | Backing field for Input. |
private readonly List<ITouchScreenButton> instantiatedButtons | Backing list for InstantiatedButtons, the spawned keys. |
private bool isShiftLocked | True while shift is locked by a double press. |
private TouchScreenKeyboard.KeyBoardEdgesInfo keyboardEdgesInfo | Row edge keys and spacing for the current layout, used to place extra keys. |
private TouchScreenKeyboardKey keyPrefab | Prefab for every key. |
private static readonly Logger logger | NLog logger for this class. |
private Vector2 originOffset | Offset added to every key position. |
private TouchScreenKeyboard.OutputEvent output | Inspector event raised with the input whenever it changes. |
private KeyboardSet pcMultiKeyboardSetup | The keyboard set MultiKeyboardSetup returns. |
private float scale | Scale from layout positions to local positions. |
private VirtualKeyboardSetup setup | Single layout used when multi-layout mode is off. |
private Renderer shiftLockMarker | Renderer shown while shift is locked. |
private float timeToDoubleShift | Real time until which a second shift press locks shift. |
private bool useMultiKeyboardSetup | When true the keyboard uses a keyboard set with switchable layouts instead of one layout. |
Properties
| Member | What it is |
|---|---|
float BackspaceDelayStart { get; } | Seconds a held backspace waits before repeating. |
float BackspaceSingleLetterDuration { get; } | Seconds a held backspace deletes letter by letter before speeding up. |
float ContinuousBackspaceSpeed { get; } | Repeat speed for a held backspace. |
IUseVirtualKeyboard CurrentUser { get; private set; } | The text field currently typing on the keyboard, or null. |
string Input { get; set; } | The typed text. Setting it trims to the user's character limit and raises InputChanged. |
static TouchScreenKeyboard Instance { get; private set; } | The keyboard in the scene. |
override List<ITouchScreenButton> InstantiatedButtons { get; } | Key buttons spawned for the current layout. |
bool IsShiftPressed { get; private set; } | True while shift is on. Turns off after one character unless shift is locked. |
bool IsShowingSecret { get; } | Never set, so always false. |
Dictionary<KeyCode, FunctionKeyDefinition> MappedFunctionKeys { get; } | Function keys with their actions, by key code. |
protected override Vector2 Offset { get; } | Centre offset of the keyboard's touch area. |
2 private and internal properties
| Member | What it is |
|---|---|
private VirtualKeyboardSetup KeyboardSetup { get; } | The single layout used when useMultiKeyboardSetup is off (the setup field). |
private KeyboardSet MultiKeyboardSetup { get; } | The keyboard set used for switching layouts. Always the PC set in this build; the Android set is never read. |
Events
Methods
| Member | What it is |
|---|---|
TouchScreenKeyboardKey AddExtraKey(VirtualKeyInfo keyInfo, bool leftSide, int insertRow) | Adds a key at the left or right end of a keyboard row. |
void ApplyNewAutoCompletionSource(IAutoCompletionSource autoCompletionSource) | Sets where autocomplete suggestions come from, adding the suggestion keys the first time. |
void ClearFocus() | Removes all listeners from its events and tells the current user it lost focus. |
void EventSetUpNewKeyboard(int newKeyboardIndex) | Switches to another layout of the keyboard set (such as symbols), keeping keys that match. |
static TouchScreenKeyboard Get(Vector3 position, Quaternion rotation, IUseVirtualKeyboard newUser) | Moves the keyboard to a position and rotation, shows it, clears the input and gives it to a new user. |
void Hide(IUseVirtualKeyboard user) | Hides the keyboard if the given user is the current one. |
void KeyPressed(KeyCode key) | Handles a key: types a character, backspace, return, shift, a function key or an autocomplete pick. |
void Next() | Asks the current user to move to the next field. |
void Previous() | Asks the current user to move to the previous field. |
void SetupNewUser(IUseVirtualKeyboard newUser) | Gives the keyboard to a text field and hooks its input and submit handlers. |
void ToggleSecret() | Raises ToggleSecretDisplay. |
void TypeCustom(string custom) | Adds a string to the input. |
void WordBackspace() | Deletes the last word. |
protected override void OnDrawGizmos() | Draws the key layout in the editor. |
protected override void PostTouchCalculation() | After touch checks, lets each enabled key settle its press state. |
protected override void PreTouchCalculation() | Before touch checks, clears each enabled key's finger distance. |
protected override void UpdateTouchWithButtons(TouchScreenMenuBase.TouchInput touch) | Updates each key's distance to a nearby fingertip. |
23 private and internal methods
| Member | What it is |
|---|---|
private void AddAutoCompleteKeys() | Spawns the suggestion keys from the keyboard set's completion layout. |
private void ApplyCompletion(string completion) | Replaces the whole input with a chosen suggestion. |
private void AutoCompleteSetup() | Once only, when there's an autocomplete source: adds suggestion keys and refreshes them whenever the input changes. |
private void Awake() | Claims Instance (logs an error for a second keyboard), maps function keys, sets up for the local player and hides itself if unused. |
private void BaseKeyboardSetup(VirtualKeyboardSetup baseSetup, int lastEqualIndex) | Spawns the keys of a layout after the ones kept from the previous layout, and records row edges and the space key. |
private Vector3 CalculateTransitionKeyPosition_L_R(Vector2 edgeKeyPos, float spacing, int stackMultiplier, float spaceOffset) | Works out where an extra key goes at the left or right end of a row. |
private static TouchScreenKeyboard Get(Vector3 position, Quaternion rotation) | Moves the keyboard to a position and rotation, shows it, clears the input and gives it to a new user. |
private void GetMinMax(out Vector2 min, out Vector2 max) | Finds the bounds of the current layout's key positions. |
private void IncludeLetter(string letter) | Adds a letter to the input, upper case while shift is on. |
private void IncludeNumber(int number) | Adds a digit to the input. |
private void LocalKeyboardSetup() | Sets up the keyboard for the local player and its autocomplete. |
private void OnDestroy() | Unhooks from PlayerController.LocalPlayerSet. |
private void OnValidate() | Editor: recomputes the keyboard's dimensions when settings change. |
private void PopulateAutoCompletesWithCurrentInput(string currentInput) | Fills up to four suggestion keys with completions for the current input and hides the rest. |
private void PressShift() | Toggles shift. A second press within doubleShiftTimer locks it; another press unlocks. |
private int RemoveOnlyNecessaryKeys(int incomingIndex) | When switching layout, keeps leading keys both layouts share and destroys the rest. Returns the last shared index. |
private void ResetDimensions() | Recomputes the touch area size and offset from the layout's key bounds. |
private Vector3 ScalePosition(Vector2 original) | Turns a layout key position into a local position, using scale and originOffset. |
private void SetActive(bool isActive) | Shows or hides the keyboard GameObject. |
private void SetUpNewKeyboard(int keyboardIndex, int lastEqualIndex) | Builds a layout from the keyboard set, adding the secret-toggle key when setupSecretKey is on. |
private void SetupPlayer(PlayerController player) | Handler for the local player being set: runs LocalKeyboardSetup once. |
private TouchScreenKeyboardKey SpawnKey(VirtualKeyInfo keyInfo) | Instantiates a key from keyPrefab under the buttons parent. |
private string WordBackspace(string input) | Deletes the last word. |
Used in
Members of other types that take, return or hold a TouchScreenKeyboard:
InputFieldWithKeyboard.keyboard, InputFieldWithKeyboard.Keyboard, InputFieldWithKeyboard.keyboardPrefab, AltaAccountRegistererAndLinker.keyboard, ServerBoardFilter.keyboard, TouchScreenKeyboardKey.Setup, TouchScreenKeyboardKey.SetupCoreReferences, TouchScreenKeyboardKey.virtualKeyboard, VirtualInputField.keyboard.