2025-07-08 10:46:31 +00:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
|
|
|
|
namespace Superlazy.UI
|
|
|
|
|
{
|
|
|
|
|
public class SLUIFadeCanvasGroup : SLUIOnOffTransition
|
|
|
|
|
{
|
|
|
|
|
public float fadeInTime = 0.3f;
|
|
|
|
|
public float fadeOutTime = 0.3f;
|
|
|
|
|
|
|
|
|
|
private CanvasGroup group;
|
|
|
|
|
private float currentAlpha = 0.0f;
|
|
|
|
|
|
|
|
|
|
protected override void Validate()
|
|
|
|
|
{
|
|
|
|
|
group = GetComponent<CanvasGroup>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Init()
|
|
|
|
|
{
|
|
|
|
|
if (currentState) currentAlpha = 1.0f;
|
|
|
|
|
else currentAlpha = 0.0f;
|
|
|
|
|
|
|
|
|
|
group.alpha = currentAlpha;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnUpdate(bool forceUpdate = false)
|
|
|
|
|
{
|
|
|
|
|
var result = false;
|
|
|
|
|
if (currentState)
|
|
|
|
|
{
|
|
|
|
|
if (fadeInTime != 0) currentAlpha += Time.unscaledDeltaTime / fadeInTime;
|
|
|
|
|
else currentAlpha = 1.0f;
|
|
|
|
|
if (currentAlpha >= 1.0f)
|
|
|
|
|
{
|
|
|
|
|
currentAlpha = 1.0f;
|
|
|
|
|
result = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (fadeOutTime != 0) currentAlpha -= Time.unscaledDeltaTime / fadeOutTime;
|
|
|
|
|
else currentAlpha = 0.0f;
|
|
|
|
|
if (currentAlpha <= 0.0f)
|
|
|
|
|
{
|
|
|
|
|
currentAlpha = 0.0f;
|
|
|
|
|
result = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
group.alpha = currentAlpha;
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void ForceDisable()
|
|
|
|
|
{
|
|
|
|
|
group.alpha = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|