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);
            ScrollableCell scrollableCell = tempCell.Value.GetComponent <ScrollableCell>();
            if (currentDataIndex >= 0 && currentDataIndex < allCellsData.Count)
            {
                scrollableCell.Init(this, allCellsData [currentDataIndex], currentDataIndex);
            }
            else
            {
                scrollableCell.Init(this, null, currentDataIndex);
            }

            scrollableCell.ConfigureCell();
        }
    }
    public void InitializeWithData(IList cellDataList)
    {
        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 * NUMBER_OF_COLUMNS;

            PositionCell(tempCell.Value, currentDataIndex);
            tempCell.Value.SetActive(true);
            ScrollableCell scrollableCell = tempCell.Value.GetComponent <ScrollableCell>();
            if (currentDataIndex < cellDataList.Count)
            {
                scrollableCell.Init(this, cellDataList [i], currentDataIndex);
            }
            else
            {
                scrollableCell.Init(this, null, currentDataIndex);
            }
            scrollableCell.ConfigureCell();
        }
    }
Пример #3
0
    public virtual void Init(ScrollableAreaController controller, System.Object data, int index,
                             float cellHeight = 0.0f, float cellWidth = 0.0f, ScrollableCell parentCell = null)
    {
        this.controller = controller;
        this.dataObject = data;
        this.dataIndex  = index;

        this.cellHeight = cellHeight;
        this.cellWidth  = cellWidth;
        this.parentCell = parentCell;

        if (deactivateIfNull)
        {
            if (data == null)
            {
                this.gameObject.SetActive(false);
            }
            else
            {
                this.gameObject.SetActive(true);
            }
        }
    }