using BitStrap; using UnityEngine; using UnityEngine.UI; public class LayoutDynamicFix : MonoBehaviour { public VerticalLayoutGroup layout; public RectTransform rectTransform; public RectTransform scrollRectTransform; public ScrollRect scrollRect; public Scrollbar scrollbar; public Vector2 bottomParameter = Vector2.zero; private void Start() { Refresh(); } private void OnEnable() { Refresh(); } [Button] public void Refresh() { Transform[] componentsInChildren = base.transform.GetComponentsInChildren(false); int num = 0; for (int i = 0; i < componentsInChildren.Length; i++) { if (componentsInChildren[i].parent == base.transform) { num++; } } layout.spacing = 0f; rectTransform.sizeDelta = new Vector2(rectTransform.sizeDelta.x, (float)num * bottomParameter.x); scrollRectTransform.sizeDelta = new Vector2(scrollRectTransform.sizeDelta.x, rectTransform.sizeDelta.y); float value = scrollbar.value; if (value < 1f) { scrollbar.value += 0.01f; } else { scrollbar.value -= 0.01f; } scrollbar.value = value; scrollRect.CalculateLayoutInputVertical(); scrollRect.StopMovement(); Canvas.ForceUpdateCanvases(); } }