using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class ContentFitterController : MonoBehaviour { // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { } public void Refresh() { LayoutRebuilder.ForceRebuildLayoutImmediate(transform.GetComponent()); //Canvas.ForceUpdateCanvases(); //HorizontalOrVerticalLayoutGroup layout = GetComponent(); //if (layout) //{ // UpdateRect(layout); //} //else //{ // layout = GetComponent(); // if (layout) // { // UpdateRect(layout); // } //} } private void OnRectTransformDimensionsChange() { Debug.Log("cf刷新一次2"); Refresh(); } private IEnumerator UpdateRect() { LayoutRebuilder.ForceRebuildLayoutImmediate(transform.GetComponent()); yield return new WaitForSeconds(0.1F); var round = GetComponent(); if (round) { round.Refresh(); } } public void UpdateRect(HorizontalOrVerticalLayoutGroup layout) { if (layout is HorizontalLayoutGroup) { layout.SetLayoutHorizontal(); } if (layout is VerticalLayoutGroup) { layout.SetLayoutVertical(); } } }