Unity Study Notes (2)--about dropdown's learning

Source: Internet
Author: User

Today, the team leader let me write an interface, which used the drop-down bar, my impression is still in the previous Ngui have ready-made components, but Ugui did not have that stage, the team leader told me Ugui now also have, research a bit, found real convenient oh, today to simply say a bit about usage bar.


Dropdow


The usage is that the point meeting has a drop-down list and the selected can be displayed.
So the first question comes.

    • is how to fill in the dropdown list with the options we need to show the number we need
      First of all, encountered a non-used components do not be nervous, you can first see what the Panel has some properties, generally inspect interface is available, and some things can be changed some of the cannot be changed, such as, in Optiona,optionb,optionc there is a word Options, then we probably know that the number and content of the items to be retrieved or changed should be related to this Options .

Come and get the code first.

PublicClassUidropdownitem:monobehaviour {Dropdown dropdownitem; list<String> Tempnames;voidAwake () {Dropdownitem = Getcomponent<dropdown> (); tempnames =New list<String> (); }voidStart () {addnames (); Updatedropdownview (Tempnames); }///<summary>Brush data///</summary>///<param name= "ShowNames" ></param>PrivatevoidUpdatedropdownview (list<String> shownames) {dropdownItem.options.Clear (); Dropdown.optiondata TempData;for (int i =0; i < Shownames.count; i++) {TempData =New Dropdown.optiondata (); Tempdata.text = Shownames[i]; DROPDOWNITEM.OPTIONS.ADD (TempData); } DropdownItem.captionText.text = shownames[0]; }///<summary> ///simulation data Span class= "hljs-comment" >///</summary> private void addnames (string S1 = " small white "; string s2 =  "chubby"; string s3 = string s4 =  "pumpkin"; string s5 =  "Bao elder brother"; Tempnames.add (S1); Tempnames.add (S2); Tempnames.add (S3); Tempnames.add (S4); Tempnames.add (S5); }} 

The core of the word is in the brush data that method, the first definition of a dropdown.optiondata type, and then fill in the data, finally do not forget the last word, the value of the display to the first of the options is shownames[0], pot friends You can try to write a look at the OH
Let's take a look at the results of my run.


Yo yo yo


You've found me, too. I'm here to change the value of text only, think of the other values of how to get or change it, like an image or something.


The bottom of the dropdown


This is unity inside about dropdown of the bottom, we can see the text and image can be get,set, as well as storage optiondata is also, go to try it ~

Unity Study Notes (2)--about dropdown's learning

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.