You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
1.2 KiB
36 lines
1.2 KiB
using System.Collections; |
|
using System.Collections.Generic; |
|
using UnityEngine; |
|
using UnityEngine.UI; |
|
|
|
public class ParentSizeFitter : MonoBehaviour |
|
{ |
|
public float Spacing;//间隔 |
|
public float Height;//RectTransform中的Height |
|
|
|
// Use this for initialization |
|
void Start() |
|
{ |
|
for (int i = 0; i < transform.parent.childCount; i++) |
|
{ |
|
if (i > 0 && transform.parent.GetChild(i) == transform) |
|
{//加入第二个item开始计算 |
|
Spacing = transform.parent.GetComponent<VerticalLayoutGroup>().spacing; |
|
Height = GetComponent<RectTransform>().sizeDelta.y; |
|
|
|
float y = transform.parent.parent.parent.GetComponent<RectTransform>().sizeDelta.y; |
|
float y1 = transform.parent.parent.parent.GetComponent<RectTransform>().sizeDelta.y + Spacing + Height; |
|
|
|
transform.parent.parent.parent.GetComponent<RectTransform>().sizeDelta = |
|
new Vector2(transform.parent.parent.parent.GetComponent<RectTransform>().sizeDelta.x, |
|
transform.parent.parent.parent.GetComponent<RectTransform>().sizeDelta.y + Spacing + Height); |
|
} |
|
} |
|
} |
|
|
|
// Update is called once per frame |
|
void Update() |
|
{ |
|
|
|
} |
|
}
|
|
|