Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by RyanAchtenSoma · Oct 01, 2015 at 09:03 PM · inputfielddictionarysearchautocomplete

Restricting input field to predefined words

Hi Unity Community

I am wanting to use Unity’s UI Input Field as a means for searching predefined words, aided by autocomplete prompts. The user input needs to be restricted only to valid search terms (perhaps defined in a generic dictionary or what ever is appropriate).

Can anyone provide me any direction as to how this may be achieved w/o resorting to purchasing assets?

Many thanks in advance,

Ryan

Comment
Add comment · Show 7
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Cherno · Oct 01, 2015 at 09:16 PM 0
Share

Take a look at the char class on $$anonymous$$SDN.

avatar image RyanAchtenSoma Cherno · Oct 01, 2015 at 09:48 PM 0
Share

Hi @Cherno, thanks for your response. How could I use the char class to cross-reference against a predefined word list?

I understand I could set up a whole lot of if statements using the char class to detect (in)correct input, however this could get pretty messy in the case of a long list of valid terms so I am wondering if there is a cleaner and more efficient way of achieving this? Also, ideally this would allow for valid terms to be added to the list during runtime.

avatar image Cherno RyanAchtenSoma · Oct 01, 2015 at 10:20 PM 2
Share

I don't think a lot of if statements are needed, just one or two loops that check if the list of stored strings contains the currently entered string/group of chars.

Show more comments
Show more comments
avatar image Oribow · Oct 02, 2015 at 09:53 PM 1
Share

I think you make it more user friendly, if you let the user write anything they want and just give a list with entrys from your database wich contains the input. So the user can chose, from this list. Just like google does it. Or am I understanding you wrong?

avatar image RyanAchtenSoma Oribow · Oct 03, 2015 at 02:37 PM 0
Share

Hi @Oribow

I think you’re understanding me right, thanks! You actually helped clarify for me my UI needs.

The searching functionality is intended to allow users to searching the text contents of various elements in an X$$anonymous$$L document. In some cases there may be only be as few as four available terms, others there may be many.

What I really want is to allow the users to press button of type of X$$anonymous$$L field they want to search > this pulls all available terms from X$$anonymous$$L to GUI > user can click one of these terms for a return | or | the user can search for their own defined term (restricted by the char class approach described above - prevents the user wasting their time searching for unavailable terms ) > this then pulls available term results to screen

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Oribow · Oct 03, 2015 at 03:50 PM

Try this code out. It will restrict wrong input, and it gives you a list with all matching words.

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 
 public class WordSearch : MonoBehaviour
 {
     //All words you want your user to pick from
     string[] dictionary = new string[] { "Hallo", "Input", " Abde", "Hey", "kill" };
     //the inputfield your user is typing to
     public InputField inputField;
     public bool caseSensetive;
     public bool restrictUserInput;
     ArrayList possibleWords;
 
     void Start()
     {
         inputField.onValueChange.AddListener(delegate { ValueChangeCheck(); });
         possibleWords = new ArrayList(dictionary.Length);
     }
 
     void ValueChangeCheck()
     {
         possibleWords.Clear();
         //Go through all words in your databas (could be slow with many words)
         for (int i = 0; i < dictionary.Length; i++)
         {
             //Check if the words start matches the start from the input
             if (dictionary[i].StartsWith(inputField.text, !caseSensetive, null))
                 possibleWords.Add(i);
         }
         if (possibleWords.Count == 0 && restrictUserInput)
             inputField.text = inputField.text.Remove(inputField.text.Length -1,1);
         // Iterate through all possible words
         for (int i = 0; i < possibleWords.Count; i++)
         {
             Debug.Log(dictionary[(int)possibleWords[i]]); // do something with the word
             //may display it
         }
     }
 }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

32 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

I want to make a search engine, is a dictionary the right choice? 0 Answers

Research within objects by property 2 Answers

I want to add Dictionary of strings in game 2 Answers

have player search for game objects by name 0 Answers

Create a Searcher To find [n] Text's (results) of Array[n] 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges