Ejemplo n.º 1
0
        public void MoveViewTo(int cellIndex)
        {
            if (_scrollOrientation == ScrollOrientation.Vertical)
            {
                ScrollViewCellInfo cellInfo = _cellInfos.Find(ci => ci.index == cellIndex);
                if (cellInfo == null)
                {
                    Debug.LogWarningFormat("Cell index ({0}) is out of range [0, {1}]", cellIndex, _cellInfos.Count - 1);
                    return;
                }

                float halfViewPortHeight   = _viewportHeight / 2;
                float contentHeight        = _viewContent.sizeDelta.y;
                float movableContentHeight = contentHeight - _viewportHeight;
                float cellCenterPosY       = cellInfo.position + cellInfo.size / 2;

                float normalizeHeight = (cellCenterPosY - halfViewPortHeight) / movableContentHeight;
                normalizeHeight = 1.0f - Mathf.Clamp01(normalizeHeight);

                _scrollRect.normalizedPosition = new Vector2(0, normalizeHeight);
            }
            else if (_scrollOrientation == ScrollOrientation.Horizontal)
            {
            }

            if (gameObject.activeInHierarchy)
            {
                OnScrollRectChanged(Vector2.zero);
            }
        }
Ejemplo n.º 2
0
        protected void AddActiveCell(ScrollViewCellInfo cellInfo, bool isFirst = false)
        {
            ScrollViewCell cell = _delegate.ScrollCellCreated(cellInfo.index);

            cell.info = cellInfo;

            if (_scrollOrientation == ScrollOrientation.Vertical)
            {
                cell.SetTopPositionAndHeight(cellInfo.position, cellInfo.size);
            }
            else if (_scrollOrientation == ScrollOrientation.Horizontal)
            {
            }

            if (isFirst)
            {
                _activeCells.Insert(0, cell);
            }
            else
            {
                _activeCells.Add(cell);
            }

            _delegate.ScrollCellWillDisplay(cell);
        }
Ejemplo n.º 3
0
        protected bool IsCellInsideViewPort(ScrollViewCellInfo cellInfo)
        {
            float topViewContent    = 0;
            float bottomViewContent = _viewportHeight;
            float topCell           = cellInfo.position - _contentOffsetMax.y;
            float bottomCell        = cellInfo.position + cellInfo.size - _contentOffsetMax.y;

            return(!(topCell > bottomViewContent || bottomCell < topViewContent));
        }
Ejemplo n.º 4
0
        void RecreateCellInfo()
        {
            _poolCellInfo.Return(_cellInfos);
            _cellInfos.Clear();
            int cellCount = _delegate.ScrollCellCount();

            for (int i = 0; i < cellCount; i++)
            {
                ScrollViewCellInfo cellInfo = _poolCellInfo.Get();
                cellInfo.index = i;
                cellInfo.size  = _delegate.ScrollCellSize(cellInfo.index);
                _cellInfos.Add(cellInfo);
            }
        }
Ejemplo n.º 5
0
        public void AddCell(bool isFirst = false)
        {
            ScrollViewCellInfo cellInfo = _poolCellInfo.Get();

            LazyGetViewportHeight();
            if (isFirst)
            {
                cellInfo.index    = 0;
                cellInfo.position = 0;
                cellInfo.size     = _delegate.ScrollCellSize(cellInfo.index);

                CalculateCellPosition();
                DeactiveAllCell();
                UpdateCellVisibility();
            }
            else
            {
                cellInfo.index = _cellInfos.Count;
                cellInfo.size  = _delegate.ScrollCellSize(cellInfo.index);

                if (_cellInfos.Count > 0)
                {
                    ScrollViewCellInfo lastCellInfo = _cellInfos[_cellInfos.Count - 1];
                    cellInfo.position = lastCellInfo.position + lastCellInfo.size + _spacing;
                }
                else
                {
                    cellInfo.position = _headerSpace;
                }
            }

            _cellInfos.Add(cellInfo);
            float newViewContentSize = UpdateViewContent();


            // If viewContentSize > _viewportheight, OnScrollMoveDown will be called automatically
            if (gameObject.activeInHierarchy && newViewContentSize < _viewportHeight)
            {
                if (IsCellInsideViewPort(cellInfo))
                {
                    AddActiveCell(cellInfo, isFirst);
                }
            }
        }