static void GridX(UILayout element) { var mod = element.transform as RectTransform; float x = mod.sizeDelta.x; float y = mod.sizeDelta.y; Vector2 size = element.minSize; float ay = size.y + element.interval.y; int num = (int)(y / ay); if (num < 1) { num = 1; } if (element.fillSize) { float i = y / num; float r = i / size.y; size.x = i; size.y *= r; ay = size.y + element.interval.y; } float sx = -0.5f * x; float sy = 0.5f * y; float ax = size.x + element.interval.x; if (element.extandSize) { int c = mod.childCount; int r = c / num; if (c % num > 0) { r++; } var s = mod.sizeDelta; s.x = r * ax; mod.sizeDelta = s; } for (int i = 0; i < mod.childCount; i++) { int c = i / num; int r = i % num; float ox = c * ax + 0.5f * ax + sx; float oy = sy - r * ay - 0.5f * ay; var o = mod.GetChild(i) as RectTransform; o.sizeDelta = size; o.localPosition = new Vector3(ox, oy, 0); } }