Effects/FadeIn.cs
namespace PlanetMeat;
[Group( "Planet Meat - Effects" ), Title( "Fade In" ), Icon( "blur_linear" )]
public sealed class FadeIn : Component
{
[Property] private float Speed { get; set; } = 2.0f;
IEnumerable<ModelRenderer> models = null;
public float Opacity
{
get;
set
{
field = value;
ApplyOpacity();
}
} = 0.0f;
protected override void OnStart()
{
base.OnStart();
models = Components.GetAll<ModelRenderer>( FindMode.EnabledInSelfAndDescendants );
ApplyOpacity();
}
private void ApplyOpacity()
{
if ( models is not null )
{
foreach ( var m in models )
m?.Tint = m.Tint.WithAlpha( Opacity );
}
}
protected override void OnUpdate()
{
base.OnUpdate();
if ( Opacity < 1.0f )
{
var next = Opacity + Speed * Time.Delta;
if ( next >= 0.99f )
{
Opacity = 1.0f;
Destroy();
}
else
{
Opacity = next;
}
}
}
}