Ejemplo n.º 1
0
        private void UpdateContent(int cellIndex, bool scrollingPositive)
        {
            int index = scrollingPositive ? ((cellIndex - 1) * NUMBER_OF_COLUMNS) + (visibleCellsTotalCount) : (cellIndex * NUMBER_OF_COLUMNS);

            LinkedListNode <GameObject> tempCell = null;

            int currentDataIndex = 0;

            for (int i = 0; i < NUMBER_OF_COLUMNS; i++)
            {
                this.FreeCell(scrollingPositive);
                tempCell         = GetCellFromPool(scrollingPositive);
                currentDataIndex = index + i;

                PositionCell(tempCell.Value, index + i);

                ScrollViewItemBase scrollableCell = tempCell.Value.GetComponent <ScrollViewItemBase>();
                if (currentDataIndex >= 0 && currentDataIndex < allCellsData.Count)
                {
                    scrollableCell.UpdateItemData(allCellsData[currentDataIndex]);
                }
                else
                {
                    scrollableCell.UpdateItemData(null);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// when data changed use this
        /// </summary>
        /// <param name="cellDataList"></param>
        public void InitializeWithData(IList cellDataList)
        {
            if (this.rect == null)
            {
                return;
            }
            if (cellsInUse.Count > 0)
            {
                foreach (var cell in cellsInUse)
                {
                    localCellsPool.AddLast(cell);
                }
                cellsInUse.Clear();
            }
            else
            {
                if (horizontal)
                {
                    initpostion = content.localPosition.x;
                }
                else
                {
                    initpostion = content.localPosition.y;
                }
            }

            previousInitialIndex = 0;
            initialIndex         = 0;
            content.gameObject.SetActive(true);
            LinkedListNode <GameObject> tempCell = null;

            allCellsData = cellDataList;

            setContentSize();
            firstCellPostion = FirstCellPosition;

            int currentDataIndex = 0;

            for (int i = 0; i < visibleCellsTotalCount; i++)
            {
                tempCell = GetCellFromPool(true);
                if (tempCell == null || tempCell.Value == null)
                {
                    continue;
                }
                currentDataIndex = i + initialIndex;

                PositionCell(tempCell.Value, currentDataIndex);

                tempCell.Value.SetActive(true);

                ScrollViewItemBase scrollableCell = tempCell.Value.GetComponent <ScrollViewItemBase>();
                if (currentDataIndex < cellDataList.Count)
                {
                    scrollableCell.UpdateItemData(cellDataList[i]);
                }
                else
                {
                    scrollableCell.UpdateItemData(null);
                }
            }

            UpdateScrollView(Vector2.zero);
        }