Files
aibis-dream/Assets/Scripts/Framework/OtherKit/FadeKit.cs
T

50 lines
1.5 KiB
C#

using System.Collections;
using DG.Tweening;
using UnityEngine;
using UnityEngine.UI;
namespace AibisDream.Framework
{
public static class FadeKit
{
public static IEnumerator FadeInAsync(this Image image, float duration, bool useUnscaledTime = false)
{
image.gameObject.SetActive(true);
var tweener = image.DOBlendableColor(Color.white, duration);
if (useUnscaledTime)
{
tweener.SetUpdate(true);
}
yield return tweener.WaitForCompletion();
}
public static void FadeIn(this Image image, float duration)
{
image.gameObject.SetActive(true);
var tweener = image.DOBlendableColor(Color.white, duration);
}
public static IEnumerator FadeOutAsync(this Image image, float duration, bool useUnscaledTime = false)
{
image.gameObject.SetActive(true);
var tweener = image.DOBlendableColor(Color.clear, duration);
if (useUnscaledTime)
{
tweener.SetUpdate(true);
}
yield return tweener.WaitForCompletion();
image.gameObject.SetActive(false);
}
public static void FadeOut(this Image image, float duration)
{
image.gameObject.SetActive(true);
image.DOBlendableColor(Color.clear, duration).onComplete += () =>
{
image.gameObject.SetActive(false);
};
}
}
}