using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; [ExecuteAlways] public class CustomRowGrid : LayoutGroup { [Tooltip("각 줄에 몇 개의 아이템을 배치할지 입력")] public List rowItemCounts = new List() { 3, 2, 3, 3 }; public float spacingX = 100f; // 가로 간격 public float spacingY = 100f; // 세로 간격 public float startX = 0f; // 시작 X 위치 (왼쪽 여백) public override void CalculateLayoutInputHorizontal() { base.CalculateLayoutInputHorizontal(); int childIndex = 0; for (int row = 0; row < rowItemCounts.Count; row++) { int countInRow = rowItemCounts[row]; for (int col = 0; col < countInRow; col++) { if (childIndex >= rectChildren.Count) return; float totalWidth = (countInRow - 1) * spacingX; float offsetX = -totalWidth / 2f; // 가운데 정렬 Vector2 pos = new Vector2(startX + offsetX + col * spacingX, row * -spacingY); SetChildAlongAxis(rectChildren[childIndex], 0, pos.x); SetChildAlongAxis(rectChildren[childIndex], 1, pos.y); childIndex++; } } } public override void CalculateLayoutInputVertical() { } public override void SetLayoutHorizontal() { } public override void SetLayoutVertical() { } }