Implements: BaseComponentView, IGridContainerComponentView, IComponentModelConfig
Model: GridContainerComponentModel
A grid container of items ready to automatically organize them with different configurations. The contained items can be any other UI Components.
Constraint
: Sets the way the items will be positioned in the grid.Flexible
: The items will be positioned depending on the grid width.FixedColumnCount
: The items will be positioned respecting the configured number of columns.FixedRowCount
: The items will be positioned respecting the configured number of rows.
ConstraintCount
: Represents the number of fixed columns/rows that we want to configure.- NOTE: It only applies if
Constraint
is set asFixedColumnCount
orFixedRowCount
- NOTE: It only applies if
AdaptItemSizeToContainer
: If it is set totrue
, the width of the items will try to be adapted to the width of the grid.- NOTE: It is is set to
true
, thex
value of theItemSize
parameter will be ignored.
- NOTE: It is is set to
ItemSize
: Configures the size of the items included in the grid.X
: Items width. It only applies ifAdaptItemSizeToContainer
is set to false.Y
: Items height.
SpaceBetweenItems
: Configures the distance between items.X
: Horizontal distance.Y
: Vertical distance.
MinWidthForFlexibleItems
: It will be the minimum width that the items will try to have when the grid is configured asFlexible
.- NOTE: It only applies if
Constraint
is set toFlexible
andAdaptItemSizeToContainer
is also set totrue
. This kind of configuration is commonly used to configure the grid as a "responsive" UI.
- NOTE: It only applies if
ExternalParentToAdaptSize
: If it is set with something, theAdaptItemSizeToContainer
configuration will take into account the width of the set object instead of the grid width.
void Configure(BaseComponentModel newModel)
: Fills the model and refreshes the grid component with this data.int currentItemsPerRow
: Number of items per row that fit with the current grid configuration.void SetConstraint(Constraint newConstraint)
: Set the type of constraint of the grid.void SetConstraintCount(int newConstraintCount)
: Set the number of columns/rows of the grid depending on the type of constraint set.void SetItemSizeToContainerAdaptation(bool adaptItemSizeToContainer)
: Set the item size adaptation to the container.void SetItemSize(Vector2 newItemSize)
: Set the size of each child item.void SetSpaceBetweenItems(Vector2 newSpace)
: Set the minimum width for the items when constraint is set to flexible.void SetItems(BaseComponentView prefab, int amountOfItems)
: Create the items based on the prefab passed, it will create the amount specified. All previously existing items will be removed.void SetItems(List<BaseComponentView> items)
: Set the items of the grid. All previously existing items will be removed.void AddItem(BaseComponentView item)
: Adds a new item in the grid.void RemoveItem(BaseComponentView item)
: Remove an item from the grid.List<BaseComponentView> GetItems()
: Get all the items of the grid.List<BaseComponentView> ExtractItems()
: Extract all items out of the grid.void RemoveItems()
: Remove all existing items from the grid.
- Drag the prefab to your scene.
- Drag the desired items as child of the GridContainer game object (these items can be any of our UI Components).
- Configure the model from the inspector.
- Click on [REFRESH].