44 lines
1.3 KiB
C#
44 lines
1.3 KiB
C#
// Copyright (C) 2015-2021 gamevanilla - All rights reserved.
|
|
// This code can only be used under the standard Unity Asset Store End User License Agreement.
|
|
// A Copy of the Asset Store EULA is available at http://unity3d.com/company/legal/as_terms.
|
|
|
|
using System.Collections;
|
|
using UnityEngine;
|
|
|
|
namespace UltimateClean
|
|
{
|
|
/// <summary>
|
|
/// Miscellaneous utilities.
|
|
/// </summary>
|
|
public static class Utils
|
|
{
|
|
public static IEnumerator FadeIn(CanvasGroup group, float alpha, float duration)
|
|
{
|
|
var time = 0.0f;
|
|
var originalAlpha = group.alpha;
|
|
while (time < duration)
|
|
{
|
|
time += Time.deltaTime;
|
|
group.alpha = Mathf.Lerp(originalAlpha, alpha, time / duration);
|
|
yield return new WaitForEndOfFrame();
|
|
}
|
|
|
|
group.alpha = alpha;
|
|
}
|
|
|
|
public static IEnumerator FadeOut(CanvasGroup group, float alpha, float duration)
|
|
{
|
|
var time = 0.0f;
|
|
var originalAlpha = group.alpha;
|
|
while (time < duration)
|
|
{
|
|
time += Time.deltaTime;
|
|
group.alpha = Mathf.Lerp(originalAlpha, alpha, time / duration);
|
|
yield return new WaitForEndOfFrame();
|
|
}
|
|
|
|
group.alpha = alpha;
|
|
}
|
|
}
|
|
}
|