com.alicizax.unity.animatio.../Runtime/Core/Animation/CanvasGroupAlphaTo.cs

62 lines
1.2 KiB
C#
Raw Normal View History

2025-02-07 16:05:13 +08:00
using UnityEngine;
2025-11-18 11:27:53 +08:00
namespace AlicizaX.AnimationFlow.Runtime
{
2025-02-07 16:05:13 +08:00
[Category("Animation")]
2025-11-18 11:27:53 +08:00
public class CanvasGroupAlphaTo : AnimationBaseNode<float>
{
[SerializeField]
private CanvasGroup _target;
2025-02-07 16:05:13 +08:00
public override void OnInit()
{
2025-11-18 11:27:53 +08:00
orgValue = _target.alpha;
2025-02-07 16:05:13 +08:00
}
public override void OnReset()
{
2025-11-18 11:27:53 +08:00
_target.alpha = orgValue;
2025-02-07 16:05:13 +08:00
}
2025-03-14 17:37:57 +08:00
2025-11-18 11:27:53 +08:00
public override void OnEnter()
{
if (setFrom)
{
_target.alpha = from;
2025-02-07 16:05:13 +08:00
}
2025-03-14 17:37:57 +08:00
if (Condition())
{
2025-11-18 11:27:53 +08:00
_target.alpha = to;
2025-03-14 17:37:57 +08:00
}
2025-11-18 11:27:53 +08:00
enterValue = _target.alpha;
2025-02-07 16:05:13 +08:00
}
2025-11-18 11:27:53 +08:00
public override void OnUpdate(float dt)
{
_target.alpha = Easing.Ease(easyType, enterValue, to, elapsedTime / duration);
2025-02-07 16:05:13 +08:00
}
2025-11-18 11:27:53 +08:00
public override bool Valid()
{
return _target != null;
2025-02-07 16:05:13 +08:00
}
2025-11-18 11:27:53 +08:00
public override float Duration()
{
2025-02-07 16:05:13 +08:00
return duration;
}
2025-11-18 11:27:53 +08:00
public override bool HasSubTitle()
{
2025-02-07 16:05:13 +08:00
return true;
}
2025-11-18 11:27:53 +08:00
public override string SubTitle()
{
return _target != null ? _target.name : null;
2025-02-07 16:05:13 +08:00
}
}
}