/// <summary>Here the grid adapter checks if new groups need to be created or if old ones need to be disabled or destroyed, after which it calls <see cref="UpdateCellViewsHolder(TCellVH)"/> for each remaining cells</summary> /// <seealso cref="ScrollRectItemsAdapter8{TParams, TItemViewsHolder}.UpdateViewsHolder(TItemViewsHolder)"/> /// <param name="newOrRecycled">The viewholder of the group that needs updated</param> protected override void UpdateViewsHolder(CellGroupViewsHolder <TCellVH> newOrRecycled) { // At this point there is for sure enough groups, but there may not be enough enabled cells, or there may be too much enabled cells int activeCellsForThisGroup; // If it's the last one if (newOrRecycled.itemIndex + 1 == GetItemCount()) { int totalCellsBeforeThisGroup = 0; if (newOrRecycled.itemIndex > 0) { totalCellsBeforeThisGroup = newOrRecycled.itemIndex * _Params.numCellsPerGroup; } activeCellsForThisGroup = _CellsCount - totalCellsBeforeThisGroup; } else { activeCellsForThisGroup = _Params.numCellsPerGroup; } newOrRecycled.NumActiveCells = activeCellsForThisGroup; for (int i = 0; i < activeCellsForThisGroup; ++i) { UpdateCellViewsHolder(newOrRecycled.ContainingCellViewHolders[i]); } }
/// <summary> Creates the Group viewholder which instantiates the group prefab using the provided params in <see cref="ScrollRectItemsAdapter8{TParams, TItemViewsHolder}.Init(TParams)"/></summary> /// <seealso cref="ScrollRectItemsAdapter8{TParams, TItemViewsHolder}.CreateViewsHolder(int)"/> /// <param name="itemIndex">the index of the GROUP (attention, not the CELL) that needs creation</param> /// <returns>The created group views holder </returns> protected override CellGroupViewsHolder <TCellVH> CreateViewsHolder(int itemIndex) { var instance = new CellGroupViewsHolder <TCellVH>(); instance.Init(_Params.GetGroupPrefab(itemIndex).gameObject, itemIndex, _Params.cellPrefab, _Params.numCellsPerGroup); return(instance); }
/// <summary> /// Overridden in order to call <see cref="OnBeforeRecycleOrDisableCellViewsHolder(TCellVH, int)"/> for each active cell in the group /// </summary> /// <seealso cref="SRIA{TParams, TItemViewsHolder}.OnBeforeRecycleOrDisableViewsHolder(TItemViewsHolder, int)"/> protected sealed override void OnBeforeRecycleOrDisableViewsHolder(CellGroupViewsHolder <TCellVH> inRecycleBinOrVisible, int newItemIndex) { base.OnBeforeRecycleOrDisableViewsHolder(inRecycleBinOrVisible, newItemIndex); // 2 fors are more efficient if (newItemIndex == -1) { for (int i = 0; i < inRecycleBinOrVisible.NumActiveCells; ++i) { OnBeforeRecycleOrDisableCellViewsHolder(inRecycleBinOrVisible.ContainingCellViewsHolders[i], -1); } } else { for (int i = 0; i < inRecycleBinOrVisible.NumActiveCells; ++i) { OnBeforeRecycleOrDisableCellViewsHolder(inRecycleBinOrVisible.ContainingCellViewsHolders[i], newItemIndex * _Params.numCellsPerGroup + i); } } }