Skip to content

Instantly share code, notes, and snippets.

@KumoKairo
Created June 27, 2018 12:36
Show Gist options
  • Save KumoKairo/c9026f1186e924e8ca9450e20322c25d to your computer and use it in GitHub Desktop.
Save KumoKairo/c9026f1186e924e8ca9450e20322c25d to your computer and use it in GitHub Desktop.
using System;
using DG.Tweening;
using UnityEngine;
using UnityEngine.UI;
public class CheckPreferredHeight : MonoBehaviour
{
public RectTransform targetRect;
private RectTransform _currentRect;
private float _preferredHeight = 0f;
void Start()
{
_currentRect = transform as RectTransform;
}
void Update()
{
var currentlyPreferredHeight = LayoutUtility.GetPreferredHeight(targetRect);
currentlyPreferredHeight = Mathf.Max(180f, currentlyPreferredHeight);
if (Math.Abs(_preferredHeight - currentlyPreferredHeight) > 0.01f)
{
_preferredHeight = currentlyPreferredHeight;
_currentRect
.DOSizeDelta(new Vector2(_currentRect.sizeDelta.x, _preferredHeight + 180f), 0.2f)
.SetEase(Ease.OutBack)
.SetDelay(0.2f);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment