Beispiel #1
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);
    }