OverviewUIInput is a script that makes it possible to type in an area, allowing you to create input fields and editable text boxes.
To create an input field, just add it to any clickable area and choose a
Label that it will be modifying.
The most basic setup for an input field would be a sliced
Sprite for the background (or a
Widget if you want it to be invisible), and a child
Label for the foreground. In this example, the sprite would need a
Box Collider in order to receive events, and the
UIInput script would go onto it as well:
Clickable Area (UISprite, BoxCollider, UIInput)
- Text (UILabel)
This setup is all that's needed in order to be able to click on the input field and start typing.
You can give your Input Field a
Starting Value if you like, and you can also make it automatically save its value by giving it a key in the
Saved As field. If specified, the value you typed will be persistent. Most obvious usage of this would be for a Player Name or a Username field.
You can set the
inactive text on the input field by modifying the text of the label itself. This includes the label's color. So if you wanted a half-faded out "press here to start typing" text to be visible when the input field has no text in it, enter that text on your
label and set the label's color to be half-transparent (or just modify the
Inactive color field on the UIInput).
When the input field gets selected, the label's text will be replaced, and its color will be changed to the
Active Text color value specified on the UIInput.
You can change the
Input Type of your input if you need it to be a
Password Field, or if you want there to be auto-correcting behaviour on mobile platforms. The
Keyboard Type is also there for mobile platforms, as it controls what kind of keyboard will show up when you select the input field.
If you want the input field to have some basic validation, such as making it accept only
Integer values, set it using the
Validation option. You can likewise limit the number of characters that the user will be allowed to enter using the
Character Limit field. Leaving it at zero removes the character limit.
To allow your user to use Tab to navigate to the next field, drag & drop the next input field into the
Select On Tab field.
To change the alignment of your input field, modify it on the
Label itself. You can similarly limit your input field to a
single line by setting the
Max Lines property to 1 on the
UILabel. The same goes for all the other options on the label, such as giving it a gradient, a shadow effect, or changing the character spacing.
Note that in most cases you will likely want to leave your label's
Overflow handling on
ClampContent, as this will allow the input to automatically scroll to the right as the user keeps typing past the original bounds.
To receive a notification of when the user submits the text in the input field, take advantage of its
On Submit notification section. You can always retrieve the input field's value within the function you're calling by using
UIInput.current.value. After you're done processing the callback you can set the UIInput.current.value to null to clear the input field's text:
public void MySubmitFunction ()
{
Debug.Log("I typed: " + UIInput.current.value);
UIInput.current.value = null;
}
Pro-TipIf you want to be able to select your input field when pressing a specific key, such as hitting "Enter" to start typing in your chat window, attach a
UIKeyBinding script to it.
Class Documentationhttp://tasharen.com/ngui/docs/class_u_i_input.htmlIf you have a question regarding this component or would like me to clarify something, just post a reply here.