using System.Collections; using System.Collections.Generic; using UnityEngine; [ExecuteAlways] public class AutoListPositioner : MonoBehaviour { public float Padding; public List SpecificPaddings; private void Update() { if (!Application.isPlaying) { for (int Index = SpecificPaddings.Count; Index < transform.childCount - 1; Index++) { SpecificPaddings.Add(Padding); } RectTransform Parent = GetComponent(); float Y = Parent.position.y; for (int Index = 0; Index < transform.childCount; Index++) { RectTransform Child = transform.GetChild(Index).GetComponent(); if (Child) { Child.position = new Vector2(Child.position.x, Y); if (Index < SpecificPaddings.Count) { Y -= Child.rect.height + SpecificPaddings[Index]; } } else { Debug.LogWarning($"AutoListPositioner {name} has non-UI children!"); } } } } }