Created
June 27, 2018 12:36
-
-
Save KumoKairo/c9026f1186e924e8ca9450e20322c25d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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