Beispiel #1
0
    void SetItemDisplay(bool isRebuild = false)
    {
        if (content == null)
        {
            throw new Exception("SetItemDisplay Exception: content is null !");
        }

        //计算已显示的哪些需要隐藏
        for (int i = 0; i < m_items.Count; i++)
        {
            m_items[i].OnDrag();

            //已经完全离开了显示区域
            if (!m_viewBounds.Intersects(GetItemBounds(m_items[i].m_index)))
            {
                ReusingScrollItemBase itemTmp = m_items[i];
                m_items.Remove(itemTmp);
                itemTmp.OnHide();

                if (!isRebuild)
                {
                    //隐藏并移到缓存
                    itemTmp.gameObject.SetActive(false);
                }
                m_itemCaches.Add(itemTmp);

                m_indexList[itemTmp.m_index].status = ReusingStatus.Hide;
            }
        }

        //计算出哪些需要显示
        //如果有未显示的则显示出来,从对象池取出对象
        bool m_clip = false;

        for (int i = 0; i < m_indexList.Count; i++)
        {
            if (m_indexList[i].status == ReusingStatus.Hide)
            {
                if (m_viewBounds.Intersects(GetItemBounds(m_indexList[i].index)))
                {
                    ShowItem(i, isRebuild, m_datas[i]);


                    m_indexList[i].status = ReusingStatus.Show;
                    m_clip = true;
                }
                else
                {
                    if (m_clip)
                    {
                        break;
                    }
                }
            }
            else
            {
                m_clip = true;
            }
        }
    }
    void SetItemDisplay()
    {
        m_clip = false;
        //计算已显示的哪些需要隐藏
        for (int i = 0; i < m_items.Count; i++)
        {
            m_items[i].OnDrag();

            if (!m_clip)
            {
                m_startPos = m_items[i].m_index;
                m_clip     = true;
            }
            else
            {
                if (m_startPos > m_items[i].m_index)
                {
                    m_startPos = m_items[i].m_index;
                }
            }

            //已经完全离开了显示区域
            if (!m_viewBounds.Intersects(GetItemBounds(m_items[i].m_index)))
            {
                ReusingScrollItemBase itemTmp = m_items[i];
                m_items.Remove(itemTmp);
                itemTmp.OnHide();

                //隐藏并移到缓存
                itemTmp.gameObject.SetActive(false);
                m_itemCatchs.Add(itemTmp);

                m_indexList[itemTmp.m_index].status = ReusingStatus.Hide;
            }
        }

        if (m_startPos > 0)
        {
            m_startPos--;
        }

        //Debug.Log(m_startPos);

        m_clip = false;

        //计算出哪些需要显示
        //如果有未显示的则显示出来,从对象池取出对象
        for (int i = m_startPos; i < m_indexList.Count; i++)
        {
            if (m_indexList[i].status == ReusingStatus.Hide)
            {
                if (m_viewBounds.Intersects(GetItemBounds(m_indexList[i].index)))
                {
                    ShowItem(i, m_datas[i]);
                    m_indexList[i].status = ReusingStatus.Show;
                    m_clip = true;
                }
                else
                {
                    if (m_clip)
                    {
                        break;
                    }
                }
            }
            else
            {
                m_clip = true;
            }
        }
    }