OverviewA toggle is a generic component that has two states: on, and off. Toggle can be used to create checkboxes, tabs, radio button groups, and other similar widgets.
Toggle is a perfect example of a small to-the-point component that can be used to do a lot of things. Like most NGUI controls, the look of it is not hard-coded for you like it is in other systems. Instead, it's used in combination with other scripts to achieve the desired behaviour.
By itself, the toggle is simply capable of fading in and fading out the targeted object. Generally this "object" is a checkmark, a highlighted sprite, or some other indicator of an active state.
To create a basic checkbox, create a pair of sprites -- a background, and a foreground (make it a child of the background to make it simple). For the background choose something that looks like a button. For the foreground choose something that looks like a checkmark.
Attach the UIToggle script to the parent (the background), and reference the foreground in the UIToggle's
Sprite parameter. That's it, you now have a checkbox.
You can turn it into a
Radio Button by specifying a
Group ID other than zero. Just set up your checkbox how you want it to be, give it a group ID, and duplicate your checkbox game object a couple of times (CTRL+D with it selected).
You can create an Animation to make your checkmark transition smoother, or just attach an Animation component to your Checkmark and reference the provided "Checkmark" animation clip. Reference this clip in the
Animation field on your Toggle, and you will have an even better looking transition.
If you want your toggle to start active, check the
Starting State checkbox.
Pro-TipYou can create a tab using a Toggle by creating two sprites, one on top of the other. First create a dark sprite, then add a child to it and make it brighter. Attach a Toggle component to the dark sprite's object and reference the lighter sprite as the Toggle's
Sprite. Give this tab a
Group then duplicate it a few times to create a group of tabs.
Use together with the
UIToggledObjects script to set up easy enabling and disabling of child panels, thus creating a multi-tabbed window.
Class Documentationhttp://tasharen.com/ngui/docs/class_u_i_toggle.htmlIf you have a question regarding this component or would like me to clarify something, just post a reply here.