protected void RepositionVariableSize (List<Transform> children)
{
float xOffset = 0;
float yOffset = 0;
int cols = columns > 0 ? children.Count / columns + 1 : 1;
int rows = columns > 0 ? columns : children.Count;
Bounds[,] bounds = new Bounds[cols, rows];
Bounds[] boundsRows = new Bounds[rows];
Bounds[] boundsCols = new Bounds[cols];
int x = 0;
int y = 0;
for (int i = 0, imax = children.Count; i < imax; ++i)
{
Transform t = children[i];
Bounds b = NGUIMath.CalculateRelativeWidgetBounds(t);
Vector3 scale = t.localScale;
b.min = Vector3.Scale(b.min, scale);
b.max = Vector3.Scale(b.max, scale);
bounds[y, x] = b;
boundsRows[x].Encapsulate(b);
boundsCols[y].Encapsulate(b);
if (++x >= columns && columns > 0)
{
x = 0;
++y;
}
}
x = 0;
y = 0;
for (int i = 0, imax = children.Count; i < imax; ++i)
{
Transform t = children[i];
Bounds b = bounds[y, x];
Bounds br = boundsRows[x];
Bounds bc = boundsCols[y];
Vector3 pos = t.localPosition;
pos.x = xOffset + b.extents.x - b.center.x;
pos.x += b.min.x - br.min.x + padding.x;
if (direction == Direction.Down)
{
pos.y = -yOffset - b.extents.y - b.center.y;
pos.y += (b.max.y - b.min.y - bc.max.y + bc.min.y) * 0.5f - padding.y;
}
else
{
pos.y = yOffset + (b.extents.y - b.center.y);
pos.y -= (b.max.y - b.min.y - bc.max.y + bc.min.y) * 0.5f - padding.y;
}
xOffset += br.max.x - br.min.x + padding.x * 2f;
t.localPosition = pos;
if (++x >= columns && columns > 0)
{
x = 0;
++y;
xOffset = 0f;
yOffset += bc.size.y + padding.y * 2f;
}
}
}