powerfun-unity/Assets/ContentFitterController.cs

64 lines
1.6 KiB
C#
Raw Permalink Normal View History

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<RectTransform>());
//Canvas.ForceUpdateCanvases();
//HorizontalOrVerticalLayoutGroup layout = GetComponent<HorizontalLayoutGroup>();
//if (layout)
//{
// UpdateRect(layout);
//}
//else
//{
// layout = GetComponent<VerticalLayoutGroup>();
// if (layout)
// {
// UpdateRect(layout);
// }
//}
}
private void OnRectTransformDimensionsChange()
{
Debug.Log("cf刷新一次2");
Refresh();
}
private IEnumerator UpdateRect()
{
LayoutRebuilder.ForceRebuildLayoutImmediate(transform.GetComponent<RectTransform>());
yield return new WaitForSeconds(0.1F);
var round = GetComponent<ImageWithIndependentRoundedCorners>();
if (round)
{
round.Refresh();
}
}
public void UpdateRect(HorizontalOrVerticalLayoutGroup layout)
{
if (layout is HorizontalLayoutGroup)
{
layout.SetLayoutHorizontal();
}
if (layout is VerticalLayoutGroup)
{
layout.SetLayoutVertical();
}
}
}