标签:
using System.Collections.Generic; using UnityEngine; /// + Scroll View /// |- UIWrappedContent /// |-- Item 1 /// |-- Item 2 /// |-- Item 3 /// public class LoopContent : UIWrapContent { protected override void Start() { base.Start(); onInitializeItem = OnUpdateItem; WrapItem[] items = this.GetComponentsInChildren<WrapItem>(); for (int i = 0; i < items.Length; i++) { items[i].SetValue(Manager.GetData()[i]); } } private void OnUpdateItem(GameObject go, int index, int realIndex) { go.GetComponent<WrapItem>().SetValue(realIndex); } }
using UnityEngine; using System.Collections; public class WrapItem : MonoBehaviour { public UILabel lb_Name; public void SetValue(int index) { lb_Name.text = Manager.GetData()[index].ToString(); } }
public class Manager { public static List<int> GetData() { List<int> nums = new List<int>(); for (int i = 0; i < 20; i++) nums.Add(i); return nums; } }
标签:
原文地址:http://www.cnblogs.com/HelloUnity/p/5462396.html