Hello!
I’m happy to present the Autocompletion for InputField asset. It is a simple element that suggests words considering the letters already input by the user (v1.01). The words suggested are imported from a text file; for the given x letters input will be presented words that share the same x first letters.
The difficulty of this asset was repurposing the InputField Element class so that it would not interfere with the word list functionalities (navigating with arrows, accepting, activating and deactivating) but still keep the focus, know when to release it, etc.
How-To:
In the menu select: GameObject/UI/Autocomplete.
This asset is made of height different GameObjects (InputFieldModified elements, AutoCompletion elements, Scrollbar elements) that need to be set up in precise ways. That’s why adding it via the menu is the simplest solution.
Now, you only need to choose a text file, containing the list of words, as a TextAsset and it’s ready!
Features:
-
As well as the two example scenes linked below, there is an additional scene with 13 different styles as examples of presentation.
-
It works with the three line types of InputField.
-
The word list can be navigated thanks to the up and down arrows, the mousewheel and the scrollbar.
-
The suggestion list is toggled with the tab key, it activates when the user as entered the set minimum number of letters.
-
It deactivates when: a punctuation character is entered; the escape key is pressed; a mouse click is registered; a word is chosen.
-
This element is “border-aware”, it will not display out of the screen. It will be repositioned above the text or farther left if it was to appear off the screen.
Options:
-
Force Choose: if true the selected word will be chosen and inserted into the InputField’s text when a punctuation character is entered.
-
Respect Case: if true, the chosen word will not replace the part of the word that is already input.
-
Activate On BackSpace: if true, the suggestion list will activate when deleting letters with the backspace key.
-
Delay: the delay before the suggestion list activates, it starts anew after each new letter typed**.**
-
Offset: X and Y offsets applied to the suggestion list relative to the word being typed by the user.
-
Min Letters To Activate: how many letters are needed before activation.
-
Max Words Displayed: how many words are displayed in one page of the suggestion list**.**
-
Max Words Proposed: how many words are displayed in total in the suggestion list.
Links:
- Stress test demo (79,339 words).
The source code is fully documented and available of course.