12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class ShuaXIn : MonoBehaviour
- {
-
- void Start()
- {
-
- }
- private void OnEnable() {
-
- StartCoroutine(yc());
- }
- private void OnDisable() {
- StopAllCoroutines();
- }
- IEnumerator yc()
- {
- while (true)
- {
-
- yield return new WaitForSeconds(0.2f);
- refsize();
- }
- }
- public void refcsf(Transform t)
- {
- ContentSizeFitter[] csf1 = t.transform.GetComponentsInChildren<ContentSizeFitter>();
- for (int i = csf1.Length-1;i>0;i--)
- {
- if(this.transform!=csf1[i].transform)
- {
- refcsf(csf1[i].transform);
- }
- csf1[i].SetLayoutHorizontal();
- csf1[i].GetComponent<VerticalLayoutGroup>()?.SetLayoutHorizontal();
- csf1[i].SetLayoutVertical();
- csf1[i].GetComponent<VerticalLayoutGroup>()?.SetLayoutVertical();
- }
- this.GetComponent<VerticalLayoutGroup>()?.SetLayoutHorizontal();
- this.GetComponent<VerticalLayoutGroup>()?.SetLayoutVertical();
- this.GetComponent<ContentSizeFitter>()?.SetLayoutHorizontal();
- this.GetComponent<ContentSizeFitter>()?.SetLayoutVertical();
- }
- public void refsize()
- {
- float y =0;
- ContentSizeFitter[] csf1 = this.transform.GetComponentsInChildren<ContentSizeFitter>();
- for (int i = csf1.Length-1;i>=0;i--)
- {
- if(csf1[i].gameObject.activeSelf)
- {
- if(this.transform!=csf1[i].transform&&csf1[i].transform.parent==this.transform)
- {
- y+=csf1[i].GetComponent<RectTransform>().sizeDelta.y;
- }
- }
- }
- this.GetComponent<RectTransform>().sizeDelta = new Vector2(this.GetComponent<RectTransform>().sizeDelta.x,y);
- }
- }
|