Пример #1
0
    public void Initialize(IList <System.Object> dataArray, E_ScrollOption scrollOption = E_ScrollOption.ResetToZero)
    {
        m_initialized = true;
        m_dataArray   = dataArray;

        m_transNodeRoot.localPosition = Vector3.zero;
        if (m_dataArray == null || m_dataArray.Count < 1)
        {
            m_transNodeRoot.SetChildCount(0);
            m_poolSize      = 0;
            m_maxLine       = 0;
            m_firstIndexMax = 0;
            SetHeadAndTailSpritePosition();
            CachedScrollView.ResetPosition();
            return;
        }

        int visibleLines = GetVisibleLines();

        m_poolSize      = Mathf.Min(m_dataArray.Count, visibleLines * m_columnCount);
        m_maxLine       = Mathf.Max(0, (m_dataArray.Count - 1) / m_columnCount);
        m_firstIndexMax = Mathf.Max(0, m_dataArray.Count - m_poolSize);

        // calculate the position of the head and the tail
        SetHeadAndTailSpritePosition();
        m_prototype.gameObject.SetActive(true);
        // initialize prototypes
        m_transNodeRoot.SetChildCount(m_poolSize, m_prototype);
        m_prototype.gameObject.SetActive(false);
        // add prototypes into dynamic item pool
        m_dynamicNodes.Clear();
        for (int i = 0; i < m_poolSize; i++)
        {
            Transform childTrans = m_transNodeRoot.GetChild(i);
            childTrans.gameObject.SetActive(true);
            UIPoolListNode uiItem = childTrans.GetComponent <UIPoolListNode>();
            m_dynamicNodes.Add(uiItem);
        }

        m_firstIndexLastFrame = -1;
        if (scrollOption == E_ScrollOption.ResetToZero)
        {
            CachedScrollView.ResetPosition();
            UpdateItems(0);
        }
        else
        {
            if (gameObject.activeInHierarchy)
            {
                StartCoroutine(RestrictWithInBounds());
            }
            UpdateItems(GetFirstVisibleIndex());
        }
        //CachedScrollView.onDragFinished = OnPanelDragFinished;

        m_lastPull = 0;
    }
Пример #2
0
    IEnumerator RestrictWithInBounds()
    {
        yield return(null);

        if (CachedScrollView.restrictWithinPanel && CachedPanel.clipping != UIDrawCall.Clipping.None)
        {
            CachedScrollView.RestrictWithinBounds(CachedScrollView.dragEffect == UIScrollView.DragEffect.None, CachedScrollView.canMoveHorizontally, CachedScrollView.canMoveVertically);
        }
    }