64 lines
1.5 KiB
C#
64 lines
1.5 KiB
C#
using System;
|
|
using Cute;
|
|
using UnityEngine;
|
|
|
|
public class FadeUtility
|
|
{
|
|
private static readonly AnimationCurve FADE_ALPHA_ANIM_CURVE = AnimationCurve.Linear(0f, 0f, 1f, 1f);
|
|
|
|
private static void FadeOut(GameObject obj, Action onFinish)
|
|
{
|
|
UIButtonColor button = obj.GetComponent<UIButtonColor>();
|
|
float originalDuration = 0f;
|
|
if (button != null)
|
|
{
|
|
originalDuration = button.duration;
|
|
button.duration = 0f;
|
|
}
|
|
TweenColor component = obj.GetComponent<TweenColor>();
|
|
if (component != null)
|
|
{
|
|
component.enabled = false;
|
|
}
|
|
FadeOutObject(obj.AddMissingComponent<UITweenAlpha>(), delegate
|
|
{
|
|
if (button != null)
|
|
{
|
|
button.duration = originalDuration;
|
|
}
|
|
onFinish();
|
|
});
|
|
}
|
|
|
|
public static void FadeFinish(GameObject obj)
|
|
{
|
|
UITweenAlpha component = obj.GetComponent<UITweenAlpha>();
|
|
if (!(component == null))
|
|
{
|
|
component.End();
|
|
}
|
|
}
|
|
|
|
public static void FadeOutObject(UITweenAlpha tweenAlpha, Action onFinish = null)
|
|
{
|
|
if (!(tweenAlpha == null))
|
|
{
|
|
if (tweenAlpha._curve == null)
|
|
{
|
|
tweenAlpha._curve = FADE_ALPHA_ANIM_CURVE;
|
|
tweenAlpha._curve.postWrapMode = WrapMode.Once;
|
|
tweenAlpha._curve.preWrapMode = WrapMode.Once;
|
|
}
|
|
tweenAlpha._from = 1f;
|
|
tweenAlpha._to = 0f;
|
|
tweenAlpha._endTime = 0.3f;
|
|
tweenAlpha._delayTime = 0f;
|
|
tweenAlpha._finishCallBack = delegate
|
|
{
|
|
onFinish.Call();
|
|
};
|
|
tweenAlpha.PlayForward(isReset: true);
|
|
}
|
|
}
|
|
}
|