码迷,mamicode.com
首页 > 其他好文 > 详细

UIWrapContent实现Item复用

时间:2016-05-05 17:18:50      阅读:467      评论:0      收藏:0      [点我收藏+]

标签:

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;
    }
}

 

UIWrapContent实现Item复用

标签:

原文地址:http://www.cnblogs.com/HelloUnity/p/5462396.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!