OverviewAttaching a UIPopupList script to a
button will bring up a list of options for you to choose from.
To create a popup list with a set of options that will be shown when you click on some button, first add the
UIPopupList script to it and specify the
Atlas and
Font options. You will also likely want to choose specific sprites to be used for the
Background and the
Highlight. Background is the sprite used to create a background behind the popup list's item selection, and the Foreground is the sprite used to highlight the currently selected option.
To specify different options for your Popup List, simply enter them in the
Options box. It's a multi-line text box, and each line you add to it will create a new entry in the list. So if you wanted to have 3 different options -- "First", "Second" and "Third" -- you would enter them like so:
The
Font section defines what font is going to be used by labels created by the popup list. In the picture above, first, second and third option labels were all created with the "Arimo20" font specified in the inspector. Depending on the type of font used (bitmap or dynamic), you will be able to change the
Font Size and -- if using a dynamic font --
Font Style. You can also choose the
Text Color that will tint the text as well as the
Padding in between of your text and the border created using the
Background sprite from the
Atlas section.
If you don't want the popup list to animate as it appears, but simply want it to appear and disappear as needed, uncheck the
Animated option.
If you want the text options to be localized using the Localization System, check the
Localized checkbox.
In the
OnValueChange section you can specify a function that will be called when a value gets chosen in the Popup List. If you've added the label somewhere, you can easily reference its
SetCurrentSelection function, and the label's value will show the Popup List's selection. To do this, drag & drop the Label's game object into the
Notify field and then choose the UILabel.SetCurrentSelection function from the drop-down list.
To add a change listener via code, use the EventDelegate.Add function:
EventDelegate.Add(popupList.onChange, YourFunction);
...where YourFunction is of void FuncName(void) type:
void YourFunction ()
{
Debug.Log("Selection: " + UIPopupList.current.value);
}
Pro-TipTo make a more practical popup list -- a Drop-Down List, reference the button's label in the OnValueChange field and choose its UILabel.SetCurrentSelection method. After doing so, the label's text will automatically update itself when you choose an item from the list.
Class Documentationhttp://tasharen.com/ngui/docs/class_u_i_popup_list.htmlIf you have a question regarding this component or would like me to clarify something, just post a reply here.