48 lines
1015 B
C#
48 lines
1015 B
C#
using System.Collections;
|
|
using UnityEngine;
|
|
|
|
namespace UIWidgets
|
|
{
|
|
[RequireComponent(typeof(RectTransform))]
|
|
public class SlideUp : MonoBehaviour
|
|
{
|
|
private RectTransform rect;
|
|
|
|
private void Awake()
|
|
{
|
|
rect = base.transform as RectTransform;
|
|
}
|
|
|
|
public void Run()
|
|
{
|
|
StartCoroutine(StartAnimation());
|
|
}
|
|
|
|
private IEnumerator StartAnimation()
|
|
{
|
|
yield return StartCoroutine(AnimationCollapse());
|
|
base.gameObject.SetActive(false);
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
Notify.FreeSlide(rect);
|
|
}
|
|
|
|
private IEnumerator AnimationCollapse()
|
|
{
|
|
float max_height = rect.rect.height;
|
|
float speed = 200f;
|
|
float time = max_height / speed;
|
|
float end_time = Time.time + time;
|
|
while (Time.time <= end_time)
|
|
{
|
|
float height = Mathf.Lerp(max_height, 0f, 1f - (end_time - Time.time) / time);
|
|
rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, height);
|
|
yield return null;
|
|
}
|
|
rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, max_height);
|
|
}
|
|
}
|
|
}
|