(19th) unity4.6 learn Ugui Chinese Document ------- create Scroll-lists, uguiscroll-lists at run time

Source: Internet
Author: User

(19th) unity4.6 learn Ugui Chinese Document ------- create Scroll-lists, uguiscroll-lists at run time


Sun Guangdong 2015.5.10

First, you must store the content in the form of scroll and list. Use the Scroll Rect component. You can scroll, but sometimes we do not want to, the item is displayed when it exceeds the region: You need to use the Mask component. Note that the Mask component group works with the Image.

 

The following figure shows the situation where the Avatar is a sub-object Image ]. 1. The parent object only has the Mask component. 2. There are the Mask and Image components. [the Image is none]. 3. There are the Mask and Image components. [The Image has an Alpha transparent area]

How can we manage items in the list container? VerticalLayout Group component to achieve automatic layout [the spacing between items can be set ]. Before that, add the Layout Element component for each item. You can set the width and height of each item .]

 

Before we finish, we need to dynamically add content in the list container during the running, so we hope that each addition will be added from the end. If there are few items, set the list container ].

In this way, we are adding the ContextSizeFitter component to the list container. What is the purpose?

 

From the corresponding relationship below, we should understand it!

 

Note: The ALT and Shift keys are different! This option is very important and will save a lot of manual settings!

 

Code involved:

Using UnityEngine; using UnityEngine. UI; using UnityEngine. eventSystems; using System. collections; using System. collections. generic; [System. serializable] public class Item {public string name; public Sprite icon; public string type; public string rarity; public bool isChampion; public Button. buttonClickedEvent thingToDo;} public class CreateScrollList: MonoBehaviour {public GameObject sampleButton; public Lis T <Item> itemList; public Transform contentPanel; void Start () {PopulateList ();} void PopulateList () {foreach (var item in itemList) {GameObject newButton = Instantiate (sampleButton) as GameObject; SampleButton button = newButton. getComponent <SampleButton> (); button. nameLabel. text = item. name; button. icon. sprite = item. icon; button. typeLabel. text = item.type=button.rar ityLabel. text = item.rar ity; Ton. championIcon. setActive (item. isChampion); // button. button. onClick = item. thingToDo; newButton. transform. setParent (contentPanel) ;}/// <summary> // the two functions assign values to the thingToDo variable through the Inspector panel. Then OK // </summary> public void SomethingToDo () {Debug. log ("I done did something! ");} Public void SomethingElseToDo (GameObject item) {Debug. Log (item. name );}}

using UnityEngine;using UnityEngine.UI;using System.Collections;public class SampleButton : MonoBehaviour {public Button button;public Text nameLabel;public Image icon;public Text typeLabel;public Text rarityLabel;public GameObject championIcon;}

Using UnityEngine; using System. collections; public class StandaloneScriptExample: MonoBehaviour {// the two functions assign values to the thingToDo variable through the Inspector panel and OKpublic void DoANewThing () {Debug. log ("Stand alone script example! ");}}



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.