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

59 lines
1.4 KiB
C#

using UnityEngine;
using UnityEngine.UI;
namespace AlicizaX.AnimationFlow.Runtime
{
[Category("Animation")]
public class GraphicAlphaTo : AnimationBaseNode<float>
{
[SerializeField]
private Graphic _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 = 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;
}
}
}