com.alicizax.unity.animatio.../Runtime/Core/Animation/SpriteRendererAlphaTo.cs
陈思海 11e5744b46 init
2025-02-07 16:05:13 +08:00

55 lines
1.5 KiB
C#

using UnityEngine;
namespace AlicizaX.AnimationFlow.Runtime {
[Category("Animation")]
public class SpriteRendererAlphaTo : ActionNode {
public float duration = 1f;
public EaseType easyType;
public SpriteRenderer target;
public bool setFrom;
public float from;
public float to;
protected float orgValue;
protected float enterValue;
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;
}
}
}