namespace GFramework.Godot.Text.Effects;
///
/// 为文本提供逐字符淡入效果。
///
[GlobalClass]
[Tool]
public partial class RichTextFadeInEffect : RichTextEffectBase
{
private readonly bool _animatedEffectsEnabled;
///
/// 初始化淡入效果。
///
/// 是否允许动态效果实际生效。
public RichTextFadeInEffect(bool animatedEffectsEnabled = true)
{
_animatedEffectsEnabled = animatedEffectsEnabled;
}
///
/// 获取标签名。
///
protected override string TagName => "fade_in";
///
/// 应用淡入动画。
///
/// 当前字符上下文。
/// 始终返回 。
public override bool _ProcessCustomFX(CharFXTransform charFx)
{
if (!_animatedEffectsEnabled)
{
return true;
}
var speed = GetFloat(charFx, "speed", 4.0f);
var tick = GetFloat(charFx, "tick", 0.01f);
var progress = (float)(charFx.ElapsedTime * speed - charFx.RelativeIndex * tick);
var color = charFx.Color;
color.A = Mathf.Clamp(progress, 0f, 1f);
charFx.Color = color;
ApplyVisibility(charFx);
return true;
}
}