Ngui scrollview dynamically add item (you do not need gameobject. Find () to find game objects that need to be dynamically changed)

Source: Internet
Author: User

I learned from the online prompts, but I forgot to save the specific website, so I cannot store it here!If you need to specify the source, contact me.

PS: I did not elaborate on the details on the Internet. I made some code implementation and sorted it out.

Next I will use the uitable component instead of uigrid to sort items.

Make the item into a preset body, such as 3: questlog (this go corresponds to questlog in the official example)

 

Mount the script on the go Object questlog In the preset questlogprefab. For example, in step 1: Name the script questlogprefab (of course, the same class name is used), and then declare the go object in the script that needs to dynamically change data, remember to make public (visible in the editor), such as mtitle label and mcount label in the above figure (corresponding to the variables in the following scripts respectively)

  

After the program is started, the above mtitle label, mcount label, and so on will be initialized before start () (because it has been bound in the editor)

After loading the preset body, obtain the variables in the script based on the corresponding class name questlogprefab (the benefit is that you do not need to use gameobject. Find () to find go !!!) :

 

Then, see questlog in 2 (A gameobject)

 

The class includes two public member variables: mtestuitablego (the parent object questlog of the preset body item) and mtestuitable. In the script

  

BTW, dynamic deletion, You can first use the remove item method in uitable (the name is missing -_-!), Then use destroy to destroy the loaded and preset body items (PS: if your application often dynamically creates and deletes items, it is best to create a recycle pool: reset the pre-body before removing it, save it to the List, and take it in the list if needed. If the list is empty, load the pre-body item .)

PS: I did not proofread the text when I typed it. If there are errors or other problems to be improved, please point them out. Thank you very much!

End: reprinted. Please specify the source!

Ngui scrollview dynamically add item (you do not need gameobject. Find () to find game objects that need to be dynamically changed)

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.