/// <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. /// <para>Override it (and call the base implementation!) only if you know what you're doing. If you just want to update your cells' views, do it in <see cref="UpdateCellViewsHolder(TCellVH)"/></para> /// </summary> /// <seealso cref="OSA{TParams, TItemViewsHolder}.UpdateViewsHolder(TItemViewsHolder)"/> /// <param name="newOrRecycled">The viewsholder of the group that needs updated</param> protected override void UpdateViewsHolder(CellGroupViewsHolder <TCellVH> newOrRecycled) { // At this point there are enough groups for sure, but there may not be enough enabled cells, or there may be too many enabled cells int activeCellsForThisGroup; // If it's the last one if (newOrRecycled.ItemIndex + 1 == GetCellGroupsCount()) { int totalCellsBeforeThisGroup = 0; if (newOrRecycled.ItemIndex > 0) { totalCellsBeforeThisGroup = newOrRecycled.ItemIndex * _Params.CurrentUsedNumCellsPerGroup; } activeCellsForThisGroup = _CellsCount - totalCellsBeforeThisGroup; } else { activeCellsForThisGroup = _Params.CurrentUsedNumCellsPerGroup; } newOrRecycled.NumActiveCells = activeCellsForThisGroup; for (int i = 0; i < activeCellsForThisGroup; ++i) { UpdateCellViewsHolder(newOrRecycled.ContainingCellViewsHolders[i]); } }
void ConfigureCellsLayoutForGroup(CellGroupViewsHolder <TCellVH> cellGroup) { for (int i = 0; i < cellGroup.ContainingCellViewsHolders.Length; i++) { var cellVH = cellGroup.ContainingCellViewsHolders[i]; _Params.ConfigureCellViewsHolderAspectRatio(cellVH); } }
/// <summary> Creates the Group viewsholder which instantiates the group prefab using the provided params in <see cref="OSA{TParams, TItemViewsHolder}.Init"/></summary> /// <seealso cref="OSA{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.grid.cellPrefab, _Params.CurrentUsedNumCellsPerGroup); return(instance); }
public virtual TCellVH GetCellViewsHolderIfVisible(CellGroupViewsHolder <TCellVH> groupVH, int withCellItemIndex) { int indexOfFirstCellInGroup = groupVH.ItemIndex * _Params.CurrentUsedNumCellsPerGroup; if (withCellItemIndex < indexOfFirstCellInGroup + groupVH.NumActiveCells) { return(groupVH.ContainingCellViewsHolders[withCellItemIndex - indexOfFirstCellInGroup]); } return(null); }
/// <summary> /// Overridden in order to call <see cref="OnBeforeRecycleOrDisableCellViewsHolder(TCellVH, int)"/> for each active cell in the group /// </summary> /// <seealso cref="OSA{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.CurrentUsedNumCellsPerGroup + i); } } }
/// <summary> This is not needed yet in case of grid adapters </summary> protected override void OnItemIndexChangedDueInsertOrRemove(CellGroupViewsHolder <TCellVH> shiftedViewsHolder, int oldIndex, bool wasInsert, int removeOrInsertIndex) { base.OnItemIndexChangedDueInsertOrRemove(shiftedViewsHolder, oldIndex, wasInsert, removeOrInsertIndex); }
/// <summary>Called for each cell in a cell group at the moment the group is first created</summary> /// <param name="cellVH"></param> /// <param name="cellGroup">The cell's group</param> protected virtual void OnCellViewsHolderCreated(TCellVH cellVH, CellGroupViewsHolder <TCellVH> cellGroup) { }