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

59 lines
1.3 KiB
C#

using UnityEngine;
namespace AlicizaX.AnimationFlow.Runtime
{
[Category("Animation")]
public class SpriteRendererAlphaTo : AnimationBaseNode<float>
{
public SpriteRenderer target;
public override void OnInit()
{
orgValue = target.color.a;
}
public override void OnReset()
{
target.color = new Color(target.color.r, target.color.g, target.color.b, orgValue);
}
public override void OnEnter()
{
if (setFrom)
{
target.color = target.color = new Color(target.color.r, target.color.g, target.color.b, from);
}
enterValue = target.color.a;
}
public override void OnUpdate(float dt)
{
float a = Easing.Ease(easyType, enterValue, to, elapsedTime / duration);
target.color = new Color(target.color.r, target.color.g, target.color.b, a);
}
public override bool Valid()
{
return target != null && duration > 0;
}
public override float Duration()
{
return duration;
}
public override bool HasSubTitle()
{
return true;
}
public override string SubTitle()
{
return target != null ? target.name : null;
}
}
}