32 lines
1.1 KiB
C#
32 lines
1.1 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
[ExecuteAlways]
|
|
public class AutoListPositioner : MonoBehaviour {
|
|
public float Padding;
|
|
public List<float> SpecificPaddings;
|
|
|
|
private void Update() {
|
|
if (Application.isEditor) {
|
|
for (int Index = SpecificPaddings.Count; Index < transform.childCount - 1; Index++) {
|
|
SpecificPaddings.Add(Padding);
|
|
}
|
|
|
|
RectTransform Parent = GetComponent<RectTransform>();
|
|
float Y = Parent.position.y;
|
|
for (int Index = 0; Index < transform.childCount; Index++) {
|
|
RectTransform Child = transform.GetChild(Index).GetComponent<RectTransform>();
|
|
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!");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|