コード例 #1
0
ファイル: EasyLayout.cs プロジェクト: zwong91/Titan
        void SetPositionsHorizontal(List <List <RectTransform> > group, Vector2 startPosition, Vector2 groupSize)
        {
            var position = startPosition;

            GetRowsWidths(group, RowsWidths);
            GetMaxColumnsWidths(group, MaxColumnsWidths);

            var align = new Vector2(0, 0);

            for (int coord_x = 0; coord_x < group.Count; coord_x++)
            {
                var row_cell_max_size = GetMaxCellSize(group[coord_x]);

                for (int coord_y = 0; coord_y < group[coord_x].Count; coord_y++)
                {
                    currentUIElement = group[coord_x][coord_y];
                    align            = GetAlignByWidth(currentUIElement, MaxColumnsWidths[coord_y], row_cell_max_size, groupSize.x - RowsWidths[coord_x]);

                    var new_position = GetUIPosition(currentUIElement, position, align);
                    if (currentUIElement.localPosition.x != new_position.x || currentUIElement.localPosition.y != new_position.y)
                    {
                        currentUIElement.localPosition = new_position;
                    }

                    position.x += ((LayoutType == LayoutTypes.Compact)
                                                ? EasyLayoutUtilites.ScaledWidth(currentUIElement)
                                                : MaxColumnsWidths[coord_y]) + Spacing.x;
                }
                position.x  = startPosition.x;
                position.y -= row_cell_max_size.y + Spacing.y;
            }
        }
コード例 #2
0
ファイル: EasyLayout.cs プロジェクト: zwong91/Titan
        void SetPositionsVertical(List <List <RectTransform> > group, Vector2 startPosition, Vector2 groupSize)
        {
            var position = startPosition;

            group = EasyLayoutUtilites.Transpose(group);
            GetColumnsHeights(group, ColumnsHeights);
            GetMaxRowsHeights(group, MaxRowsHeights);

            var align = new Vector2(0, 0);

            for (int coord_y = 0; coord_y < group.Count; coord_y++)
            {
                var column_cell_max_size = GetMaxCellSize(group[coord_y]);

                for (int coord_x = 0; coord_x < group[coord_y].Count; coord_x++)
                {
                    currentUIElement = group[coord_y][coord_x];

                    align = GetAlignByHeight(currentUIElement, MaxRowsHeights[coord_x], column_cell_max_size, groupSize.y - ColumnsHeights[coord_y]);

                    var new_position = GetUIPosition(currentUIElement, position, align);
                    if (currentUIElement.localPosition.x != new_position.x || currentUIElement.localPosition.y != new_position.y)
                    {
                        currentUIElement.localPosition = new_position;
                    }

                    position.y -= ((LayoutType == LayoutTypes.Compact)
                                                ? EasyLayoutUtilites.ScaledHeight(currentUIElement)
                                                : MaxRowsHeights[coord_x]) + Spacing.y;
                }
                position.y  = startPosition.y;
                position.x += column_cell_max_size.x + Spacing.x;
            }
        }
コード例 #3
0
ファイル: EasyLayout.cs プロジェクト: zwong91/Titan
 /// <summary>
 /// Gets the length.
 /// </summary>
 /// <returns>The length.</returns>
 /// <param name="ui">User interface.</param>
 /// <param name="scaled">If set to <c>true</c> scaled.</param>
 public float GetLength(RectTransform ui, bool scaled = true)
 {
     if (scaled)
     {
         return(Stacking == Stackings.Horizontal ? EasyLayoutUtilites.ScaledWidth(ui) : EasyLayoutUtilites.ScaledHeight(ui));
     }
     return(Stacking == Stackings.Horizontal ? ui.rect.width : ui.rect.height);
 }
コード例 #4
0
        void ShrinkHeightToFit(float height, List <List <LayoutElementInfo> > group)
        {
            var transposed_group = EasyLayoutUtilites.Transpose(group);

            for (int i = 0; i < transposed_group.Count; i++)
            {
                ShrinkToFit(height, transposed_group[i], Layout.Spacing.y, RectTransform.Axis.Vertical);
            }
        }
コード例 #5
0
ファイル: EasyLayout.cs プロジェクト: zwong91/Titan
        /// <summary>
        /// Gets the user interface element position.
        /// </summary>
        /// <returns>The user interface position.</returns>
        /// <param name="ui">User interface.</param>
        /// <param name="position">Position.</param>
        /// <param name="align">Align.</param>
        Vector2 GetUIPosition(RectTransform ui, Vector2 position, Vector2 align)
        {
            var pivot_fix_x = EasyLayoutUtilites.ScaledWidth(ui) * ui.pivot.x;
            var pivox_fix_y = EasyLayoutUtilites.ScaledHeight(ui) * ui.pivot.y;
            var new_x       = position.x + pivot_fix_x + align.x;
            var new_y       = position.y - EasyLayoutUtilites.ScaledHeight(ui) + pivox_fix_y - align.y;

            return(new Vector2(new_x, new_y));
        }
コード例 #6
0
ファイル: EasyLayout.cs プロジェクト: zwong91/Titan
        float GetMaxRowHeight(List <RectTransform> row)
        {
            float height = 0;

            for (int i = 0; i < row.Count; i++)
            {
                height = Mathf.Max(height, EasyLayoutUtilites.ScaledHeight(row[i]));
            }
            return(height);
        }
コード例 #7
0
ファイル: EasyLayout.cs プロジェクト: zwong91/Titan
        void GetMaxRowsHeights(List <List <RectTransform> > group, List <float> heights)
        {
            heights.Clear();
            var transposed_group = EasyLayoutUtilites.Transpose(group);

            for (int i = 0; i < transposed_group.Count; i++)
            {
                heights.Add(GetMaxRowHeight(transposed_group[i]));
            }
        }
コード例 #8
0
ファイル: EasyLayout.cs プロジェクト: zwong91/Titan
        Vector2 GetMaxCellSize(List <RectTransform> row)
        {
            float x = 0f;
            float y = 0f;

            for (int i = 0; i < row.Count; i++)
            {
                x = Mathf.Max(x, EasyLayoutUtilites.ScaledWidth(row[i]));
                y = Mathf.Max(y, EasyLayoutUtilites.ScaledHeight(row[i]));
            }

            return(new Vector2(x, y));
        }
コード例 #9
0
ファイル: EasyLayout.cs プロジェクト: zwong91/Titan
        void GetColumnsHeights(List <List <RectTransform> > group, List <float> heights)
        {
            heights.Clear();

            for (int i = 0; i < group.Count; i++)
            {
                float height = 0;
                for (int j = 0; j < group[i].Count; j++)
                {
                    height += EasyLayoutUtilites.ScaledHeight(group[i][j]);
                }
                heights.Add(height + (group[i].Count - 1) * Spacing.y);
            }
        }
コード例 #10
0
ファイル: EasyLayout.cs プロジェクト: zwong91/Titan
        void GetRowsWidths(List <List <RectTransform> > group, List <float> widths)
        {
            widths.Clear();

            for (int i = 0; i < group.Count; i++)
            {
                float width = 0f;
                for (int j = 0; j < group[i].Count; j++)
                {
                    width += EasyLayoutUtilites.ScaledWidth(group[i][j]);
                }
                widths.Add(width + (group[i].Count - 1) * Spacing.x);
            }
        }
コード例 #11
0
ファイル: EasyLayout.cs プロジェクト: zwong91/Titan
        Vector2 GetMaxCellSize(List <List <RectTransform> > group)
        {
            float x = 0f;
            float y = 0f;

            for (int i = 0; i < group.Count; i++)
            {
                for (int j = 0; j < group[i].Count; j++)
                {
                    x = Mathf.Max(x, EasyLayoutUtilites.ScaledWidth(group[i][j]));
                    y = Mathf.Max(y, EasyLayoutUtilites.ScaledHeight(group[i][j]));
                }
            }

            return(new Vector2(x, y));
        }
コード例 #12
0
ファイル: EasyLayout.cs プロジェクト: zwong91/Titan
        void GetMaxColumnsWidths(List <List <RectTransform> > group, List <float> maxColumnsWidths)
        {
            maxColumnsWidths.Clear();

            for (var i = 0; i < group.Count; i++)
            {
                for (var j = 0; j < group[i].Count; j++)
                {
                    if (maxColumnsWidths.Count <= j)
                    {
                        maxColumnsWidths.Add(0);
                    }
                    maxColumnsWidths[j] = Mathf.Max(maxColumnsWidths[j], EasyLayoutUtilites.ScaledWidth(group[i][j]));
                }
            }
        }
コード例 #13
0
ファイル: EasyLayout.cs プロジェクト: zwong91/Titan
        Vector2 GetAlignByHeight(RectTransform ui, float maxHeight, Vector2 cellMaxSize, float emptyHeight)
        {
            if (LayoutType == LayoutTypes.Compact)
            {
                return(new Vector2(
                           (cellMaxSize.x - EasyLayoutUtilites.ScaledWidth(ui)) * innerAligns[(int)InnerAlign],
                           emptyHeight * rowAligns[(int)RowAlign]
                           ));
            }
            else
            {
                var cell_align = groupPositions[(int)CellAlign];

                return(new Vector2(
                           (cellMaxSize.x - EasyLayoutUtilites.ScaledWidth(ui)) * (1 - cell_align.x),
                           (maxHeight - EasyLayoutUtilites.ScaledHeight(ui)) * cell_align.y
                           ));
            }
        }
コード例 #14
0
ファイル: EasyLayout.cs プロジェクト: zwong91/Titan
        /// <summary>
        /// Calculates the size of the group.
        /// </summary>
        /// <returns>The group size.</returns>
        /// <param name="group">Group.</param>
        Vector2 CalculateGroupSize(List <List <RectTransform> > group)
        {
            float width = 0f;

            if (LayoutType == LayoutTypes.Compact)
            {
                for (int i = 0; i < group.Count; i++)
                {
                    float row_width = Spacing.x * (group[i].Count - 1);
                    for (int j = 0; j < group[i].Count; j++)
                    {
                        row_width += EasyLayoutUtilites.ScaledWidth(group[i][j]);
                    }
                    width = Mathf.Max(width, row_width);
                }
            }
            else
            {
                GetMaxColumnsWidths(group, MaxColumnsWidths);
                for (int i = 0; i < MaxColumnsWidths.Count; i++)
                {
                    width += MaxColumnsWidths[i];
                }
                width += MaxColumnsWidths.Count * Spacing.x - Spacing.x;
            }

            float height = Spacing.y * (group.Count - 1);

            for (int i = 0; i < group.Count; i++)
            {
                float row_height = 0f;
                for (int j = 0; j < group[i].Count; j++)
                {
                    row_height = Mathf.Max(row_height, EasyLayoutUtilites.ScaledHeight(group[i][j]));
                }
                height += row_height;
            }

            width  += PaddingInner.Left + PaddingInner.Right;
            height += PaddingInner.Top + PaddingInner.Bottom;

            return(new Vector2(width, height));
        }
コード例 #15
0
ファイル: EasyLayout.cs プロジェクト: zwong91/Titan
        void ResizeChild(RectTransform child)
        {
            DrivenTransformProperties driven_properties = DrivenTransformProperties.None;

            if (ChildrenWidth != ChildrenSize.DoNothing)
            {
                driven_properties |= DrivenTransformProperties.SizeDeltaX;
                var width = (max_width != -1) ? max_width : EasyLayoutUtilites.GetPreferredWidth(child);
                child.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, width);
            }
            if (ChildrenHeight != ChildrenSize.DoNothing)
            {
                driven_properties |= DrivenTransformProperties.SizeDeltaY;
                var height = (max_height != -1) ? max_height : EasyLayoutUtilites.GetPreferredHeight(child);
                child.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, height);
            }

            propertiesTracker.Add(this, child, driven_properties);
        }
コード例 #16
0
        void SetPositionsVertical(List <List <LayoutElementInfo> > group)
        {
            var start_position = GetStartPosition();
            var position       = start_position;
            var height         = Layout.UISize.y;

            GetMaxRowsHeights(group);

            group = EasyLayoutUtilites.Transpose(group);
            GetColumnsHeights(group);

            var align = new Vector2(0, 0);

            for (int coord_y = 0; coord_y < group.Count; coord_y++)
            {
                var column_cell_max_size = GetMaxCellSize(group[coord_y]);

                for (int coord_x = 0; coord_x < group[coord_y].Count; coord_x++)
                {
                    element = group[coord_y][coord_x];

                    align = GetAlignByHeight(element, MaxRowsHeights[coord_x], column_cell_max_size, height - ColumnsHeights[coord_y]);

                    var new_position = GetUIPosition(element, position, align);
                    if (element.Rect.localPosition.x != new_position.x || element.Rect.localPosition.y != new_position.y)
                    {
                        element.Rect.localPosition = new_position;
                    }

                    position.y -= ((Layout.LayoutType == LayoutTypes.Compact)
                                                ? element.Height
                                                : MaxRowsHeights[coord_x]) + Layout.Spacing.y;
                }
                position.y  = start_position.y;
                position.x += column_cell_max_size.x + Layout.Spacing.x;
            }
        }
コード例 #17
0
        void ResizeColumnWidthToFit(float width, List <List <LayoutElementInfo> > group)
        {
            var transposed_group = EasyLayoutUtilites.Transpose(group);

            ResizeToFit(width, transposed_group, Layout.Spacing.x, RectTransform.Axis.Horizontal);
        }
コード例 #18
0
ファイル: EasyLayout.cs プロジェクト: zwong91/Titan
        List <List <RectTransform> > GroupUIElements()
        {
            var base_length = GetLength(rectTransform, false);

            base_length -= (Stacking == Stackings.Horizontal) ? (GetMarginLeft() + GetMarginRight()) : (GetMarginTop() + GetMarginBottom());

            var ui_elements = GetUIElements();

            ClearUIElementsGroup();
            if (LayoutType == LayoutTypes.Compact)
            {
                EasyLayoutCompact.Group(ui_elements, base_length, this, uiElementsGroup);

                if (Stacking == Stackings.Vertical)
                {
                    uiElementsGroup = EasyLayoutUtilites.Transpose(uiElementsGroup);
                }
            }
            else
            {
                GridConstraintCount = Mathf.Max(1, GridConstraintCount);
                if (GridConstraint == GridConstraints.Flexible)
                {
                    EasyLayoutGrid.GroupFlexible(ui_elements, base_length, this, uiElementsGroup);
                }
                else if (GridConstraint == GridConstraints.FixedRowCount)
                {
                    if (Stacking == Stackings.Vertical)
                    {
                        EasyLayoutGrid.GroupByRowsVertical(ui_elements, this, GridConstraintCount, uiElementsGroup);
                    }
                    else
                    {
                        EasyLayoutGrid.GroupByRowsHorizontal(ui_elements, this, GridConstraintCount, uiElementsGroup);
                    }
                }
                else if (GridConstraint == GridConstraints.FixedColumnCount)
                {
                    if (Stacking == Stackings.Vertical)
                    {
                        EasyLayoutGrid.GroupByColumnsVertical(ui_elements, this, GridConstraintCount, uiElementsGroup);
                    }
                    else
                    {
                        EasyLayoutGrid.GroupByColumnsHorizontal(ui_elements, this, GridConstraintCount, uiElementsGroup);
                    }
                }
            }

            if (!TopToBottom)
            {
                uiElementsGroup.Reverse();
            }

            if (RightToLeft)
            {
                uiElementsGroup.ForEach(ReverseList);
            }

            var width  = rectTransform.rect.width - (GetMarginLeft() + GetMarginRight());
            var height = rectTransform.rect.height - (GetMarginTop() + GetMarginBottom());

            if (LayoutType == LayoutTypes.Grid)
            {
                if (ChildrenWidth == ChildrenSize.FitContainer)
                {
                    EasyLayoutUtilites.ResizeColumnWidthToFit(width, uiElementsGroup, Spacing.x, PaddingInner.Left + PaddingInner.Right);
                }
                if (ChildrenHeight == ChildrenSize.FitContainer)
                {
                    EasyLayoutUtilites.ResizeRowHeightToFit(height, uiElementsGroup, Spacing.y, PaddingInner.Top + PaddingInner.Bottom);
                }
            }
            else
            {
                if (Stacking == Stackings.Horizontal)
                {
                    if (ChildrenWidth == ChildrenSize.FitContainer)
                    {
                        EasyLayoutUtilites.ResizeWidthToFit(width, uiElementsGroup, Spacing.x);
                    }
                    if (ChildrenHeight == ChildrenSize.FitContainer)
                    {
                        EasyLayoutUtilites.ResizeRowHeightToFit(height, uiElementsGroup, Spacing.y, PaddingInner.Top + PaddingInner.Bottom);
                    }
                }
                else
                {
                    if (ChildrenHeight == ChildrenSize.FitContainer)
                    {
                        EasyLayoutUtilites.ResizeHeightToFit(height, uiElementsGroup, Spacing.y);
                    }
                    if (ChildrenWidth == ChildrenSize.FitContainer)
                    {
                        EasyLayoutUtilites.ResizeColumnWidthToFit(width, uiElementsGroup, Spacing.x, PaddingInner.Left + PaddingInner.Right);
                    }
                }
            }

            return(uiElementsGroup);
        }