void Start() { // Update common group layout parameters _contentLayoutGroup.childAlignment = _contentLayoutGroupParams.childAlignment; _contentLayoutGroup.padding = _contentLayoutGroupParams.padding; // Update grid-specific Group Layout Parameters if (m_ViewType == ViewType.VerticalGrid) { float _verticalDivider = 1.0f; GridLayoutGroup contentGridLayoutGroup = (GridLayoutGroup)_contentLayoutGroup; GridLayoutParams groupParams = (GridLayoutParams)_contentLayoutGroupParams; // Set up grid dividers if (groupParams.constraint == GridLayoutGroup.Constraint.FixedColumnCount) { _verticalDivider = groupParams.constraintCount; } float cellHeight = (groupParams.cellSize.y + groupParams.spacing.y) * m_GroupItemsCount / _verticalDivider; float cellWidth = (groupParams.cellSize.x + groupParams.spacing.x) * _verticalDivider; contentGridLayoutGroup.cellSize = new Vector2(cellWidth, cellHeight); contentGridLayoutGroup.spacing = Vector2.zero; contentGridLayoutGroup.startCorner = groupParams.startCorner; } else if (m_ViewType == ViewType.Vertical) { VerticalLayoutGroup contentVerticalLayoutGroup = (VerticalLayoutGroup)_contentLayoutGroup; VerticalLayoutParams groupParams = (VerticalLayoutParams)_contentLayoutGroupParams; contentVerticalLayoutGroup.childForceExpandWidth = groupParams.forceExpandWidth; contentVerticalLayoutGroup.childForceExpandHeight = groupParams.forceExpandHeight; contentVerticalLayoutGroup.spacing = groupParams.spacing; } else if (m_ViewType == ViewType.Horizontal) { HorizontalLayoutGroup contentHorizontalLayoutGroup = (HorizontalLayoutGroup)_contentLayoutGroup; HorizontalLayoutParams groupParams = (HorizontalLayoutParams)_contentLayoutGroupParams; contentHorizontalLayoutGroup.childForceExpandWidth = groupParams.forceExpandWidth; contentHorizontalLayoutGroup.childForceExpandHeight = groupParams.forceExpandHeight; contentHorizontalLayoutGroup.spacing = groupParams.spacing; } isInitialized = true; if (populateWhenInitialized) { PopulateScrollView(); } if (m_ShowOnStart) { Show(); } }
private void AddLayoutGroupComponent(GameObject cellGroup) { LayoutGroup layoutGroup = null; // Update grid-specific Group Layout Parameters if (m_ViewType == ViewType.VerticalGrid) { GridLayoutGroup gridLayoutGroup = cellGroup.AddComponent <GridLayoutGroup>(); GridLayoutParams groupParams = (GridLayoutParams)_contentLayoutGroupParams; gridLayoutGroup.cellSize = groupParams.cellSize; gridLayoutGroup.spacing = groupParams.spacing; gridLayoutGroup.startCorner = groupParams.startCorner; gridLayoutGroup.startAxis = GridLayoutGroup.Axis.Horizontal; gridLayoutGroup.constraint = groupParams.constraint; gridLayoutGroup.constraintCount = m_GridLayoutParams.constraintCount; gridLayoutGroup.padding = new RectOffset(0, 0, 0, 0); layoutGroup = gridLayoutGroup; } else if (m_ViewType == ViewType.Vertical) { VerticalLayoutGroup verticalLayoutGroup = cellGroup.AddComponent <VerticalLayoutGroup>(); VerticalLayoutParams groupParams = (VerticalLayoutParams)_contentLayoutGroupParams; verticalLayoutGroup.childForceExpandWidth = groupParams.forceExpandWidth; verticalLayoutGroup.childForceExpandHeight = groupParams.forceExpandHeight; verticalLayoutGroup.spacing = groupParams.spacing; verticalLayoutGroup.padding = groupParams.padding; layoutGroup = verticalLayoutGroup; } else if (m_ViewType == ViewType.Horizontal) { HorizontalLayoutGroup horizontalLayoutGroup = cellGroup.AddComponent <HorizontalLayoutGroup>(); HorizontalLayoutParams groupParams = (HorizontalLayoutParams)_contentLayoutGroupParams; horizontalLayoutGroup.childForceExpandWidth = groupParams.forceExpandWidth; horizontalLayoutGroup.childForceExpandHeight = groupParams.forceExpandHeight; horizontalLayoutGroup.spacing = groupParams.spacing; horizontalLayoutGroup.padding = groupParams.padding; layoutGroup = horizontalLayoutGroup; } // Update common group layout parameters layoutGroup.childAlignment = _contentLayoutGroupParams.childAlignment; }