using System.Collections; using UnityEngine; using UnityEngine.UI; namespace GameBase { [DisallowMultipleComponent] public class UILayoutGroupFix : MonoBehaviour { [SerializeField] private bool fixOnEnable = true; [SerializeField] private bool fixWithDelay = true; const float fixDelay = 0.1f; void OnEnable() { if (!fixWithDelay && fixOnEnable) { LayoutRebuilder.ForceRebuildLayoutImmediate(GetComponent()); } else if (fixWithDelay) { StartCoroutine(FixDelay()); } } public void FixLayout() { if (!fixWithDelay) { LayoutRebuilder.ForceRebuildLayoutImmediate(GetComponent()); } else { StartCoroutine(FixDelay()); } } IEnumerator FixDelay() { yield return new WaitForSecondsRealtime(fixDelay); LayoutRebuilder.MarkLayoutForRebuild(GetComponent()); } } }