Files
bansonic_beta_main/Assets/scripts/UI/UI_Show_Anim.cs
T

47 lines
1.5 KiB
C#

using DG.Tweening;
using UnityEngine;
public class UI_Show_Anim : MonoBehaviour
{
public float animTime_Alpha = 1f;
public float animTime_Scale = 1f;
private void OnEnable()
{
Clear();
transform.localScale = Vector3.zero;
transform.DOScale(1, animTime_Scale).SetUpdate(true);
if (gameObject.Try_Get_Component(out CanvasGroup canvasGroup))
{
canvasGroup.alpha = 0;
float a = 0;
DOTween.To(() => a, (f) => { a = f; canvasGroup.alpha = f; }, 1, animTime_Alpha)
.SetUpdate(true)
.SetTarget(canvasGroup);
}
}
public void Close()
{
Clear();
transform.DOScale(0, animTime_Scale).SetUpdate(true);
if (gameObject.Try_Get_Component(out CanvasGroup canvasGroup))
{
float a = 1;
DOTween.To(() => a, (f) => { a = f; canvasGroup.alpha = f; }, 0, animTime_Alpha)
.SetUpdate(true)
.SetTarget(canvasGroup);
}
}
void Clear()
{
// Only kill tweens that belong to this UI element.
// Passing a Transform into DOTween.KillAll(...) is dangerous in Unity because Transform has an implicit bool
// conversion, which ends up calling KillAll(true) and wipes tweens globally.
transform.DOKill();
if (gameObject.Try_Get_Component(out CanvasGroup canvasGroup))
{
canvasGroup.DOKill();
}
}
}