예제 #1
0
    // Going from left to right, place one element at a time, then return the next legal element offset
    public override float PositionElements()
    {
        // Place column elements
        float nextElementX = -1 * (GetComponent <RectTransform>().sizeDelta.x / 2) + edgeMargin;

        for (int colIndex = 0; colIndex < content.Count; colIndex++)
        {
            GameObject col = content[colIndex];
            float      halfElementWidth = col.GetComponent <RectTransform>().rect.width / 2;

            TextBoxController rowTBC = col.GetComponent <TextBoxController>();
            if (rowTBC != null)
            {
                halfElementWidth = rowTBC.GetEffectiveSize().x / 2;
            }

            nextElementX += halfElementWidth;
            col.transform.localPosition = new Vector2(nextElementX, 0f);
            nextElementX += halfElementWidth;

            // Add either row margin or edge margin depending on if we are at the top element
            if (colIndex >= content.Count - 1)
            {
                nextElementX += edgeMargin;
            }
            else
            {
                nextElementX += contentMargin;
            }
        }

        return(nextElementX);
    }
예제 #2
0
    // Going from bottom to top, place one element at a time, then return the next legal element offset
    public override float PositionElements()
    {
        // Place row elements
        float nextElementY = -1 * (rt.sizeDelta.y / 2) + edgeMargin;

        for (int rowIndex = content.Count - 1; rowIndex >= 0; rowIndex--)
        {
            GameObject row = content[rowIndex];
            float      halfElementHeight = row.GetComponent <RectTransform>().rect.height / 2;

            TextBoxController rowTBC = row.GetComponent <TextBoxController>();
            if (rowTBC != null)
            {
                halfElementHeight = rowTBC.GetEffectiveSize().y / 2;
            }

            nextElementY += halfElementHeight;
            row.transform.localPosition = new Vector2(0f, nextElementY);
            nextElementY += halfElementHeight;

            // Add either row margin or edge margin depending on if we are at the top element
            if (rowIndex <= 0)
            {
                nextElementY += edgeMargin;
            }
            else
            {
                nextElementY += contentMargin;
            }
        }
        return(nextElementY);
    }
예제 #3
0
    public override float PositionElements()
    {
        float virtualEdgeMargin    = edgeMargin * scaleVector.y;
        float virtualContentMargin = contentMargin * scaleVector.y;

        // A lot like the column layout version, but with the target panel size instead of the actual window size
        float nextElementY = -1 * (parentPC.panelSize.y / 2) + virtualEdgeMargin;

        for (int rowIndex = content.Count - 1; rowIndex >= 0; rowIndex--)
        {
            GameObject row = content[rowIndex];
            float      halfElementHeight = row.GetComponent <RectTransform>().rect.height / 2 * scaleVector.y;

            TextBoxController rowTBC = row.GetComponent <TextBoxController>();
            if (rowTBC != null)
            {
                halfElementHeight = rowTBC.GetEffectiveSize().y / 2 * scaleVector.y;
            }

            nextElementY += halfElementHeight;
            row.transform.localPosition = new Vector2(0f, nextElementY);

            // Re-scale each element to fill the panel
            LayoutController rowLC = row.GetComponent <LayoutController>();
            if (rowLC != null)
            {
                rowLC.ScaleToFit(scaleVector);
            }
            else
            {
                row.transform.localScale = scaleVector;
            }

            nextElementY += halfElementHeight;

            // Add either row margin or edge margin depending on if we are at the top element
            if (rowIndex <= 0)
            {
                nextElementY += virtualEdgeMargin;
            }
            else
            {
                nextElementY += virtualContentMargin;
            }
        }
        return(nextElementY);
    }
예제 #4
0
    // Get dimensions of content  as if there were no margins
    public override Vector2 ContentDimensions()
    {
        float contentWidth  = 0f;
        float contentHeight = 0f;

        foreach (GameObject row in content)
        {
            TextBoxController rowTBC  = row.GetComponent <TextBoxController>();
            Vector2           rowSize = row.GetComponent <RectTransform>().sizeDelta;

            if (rowTBC != null)
            {
                rowSize = rowTBC.GetEffectiveSize();
            }

            contentWidth   = Mathf.Max(contentWidth, rowSize.x);
            contentHeight += rowSize.y;
        }

        return(new Vector2(contentWidth, contentHeight));
    }