35 lines
976 B
C#
35 lines
976 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class DeriveSizeFromChild : MonoBehaviour
|
|
{
|
|
RectTransform rect;
|
|
RectTransform childRect;
|
|
public float MinimumSize;
|
|
public float MinimumSizeX;
|
|
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
rect = GetComponent<RectTransform>();
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
if(childRect == null && transform.childCount > 0 && transform.GetChild(0) != null)
|
|
{
|
|
childRect = transform.GetChild(0).GetComponent<RectTransform>();
|
|
}
|
|
if (childRect != null && rect != null)
|
|
{
|
|
Debug.Log(childRect.rect);
|
|
if(childRect.rect.height > MinimumSize)
|
|
rect.sizeDelta = new Vector3(rect.sizeDelta.x, childRect.sizeDelta.y);
|
|
else
|
|
rect.sizeDelta = new Vector3(rect.sizeDelta.x, MinimumSize);
|
|
}
|
|
}
|
|
}
|