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

59 lines
1.3 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 SpriteRendererAlphaTo : AnimationBaseNode<float>
{
2025-02-07 16:05:13 +08:00
public SpriteRenderer target;
2025-11-18 11:27:53 +08:00
public override void OnInit()
{
2025-02-07 16:05:13 +08:00
orgValue = target.color.a;
}
2025-11-18 11:27:53 +08:00
public override void OnReset()
{
2025-02-07 16:05:13 +08:00
target.color = new Color(target.color.r, target.color.g, target.color.b, orgValue);
}
2025-11-18 11:27:53 +08:00
public override void OnEnter()
{
if (setFrom)
{
2025-02-07 16:05:13 +08:00
target.color = target.color = new Color(target.color.r, target.color.g, target.color.b, from);
}
2025-11-18 11:27:53 +08:00
2025-02-07 16:05:13 +08:00
enterValue = target.color.a;
}
2025-11-18 11:27:53 +08:00
public override void OnUpdate(float dt)
{
2025-02-07 16:05:13 +08:00
float a = Easing.Ease(easyType, enterValue, to, elapsedTime / duration);
target.color = new Color(target.color.r, target.color.g, target.color.b, a);
}
2025-11-18 11:27:53 +08:00
public override bool Valid()
{
2025-02-07 16:05:13 +08:00
return target != null && duration > 0;
}
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()
{
2025-02-07 16:05:13 +08:00
return target != null ? target.name : null;
}
}
}