Effects/DropIn.cs
using Sandbox.Utility;
namespace PlanetMeat;
[Group( "Planet Meat - Effects" ), Title( "Drop In" ), Icon( "keyboard_double_arrow_down" )]
public sealed class DropIn : Component
{
[Property] public bool DeleteObject { get; set; } = false;
[Property] public float Duration { get; set; } = 2.0f;
[Property] public GameObject Dropper { get; set; }
[Property] public Vector3 StartPosition { get; set; }
[Property] public Vector3 EndPosition { get; set; }
private float _progress = 0.0f;
private void Lerp( float frac )
{
Dropper.LocalPosition = StartPosition.LerpTo( EndPosition, Easing.EaseIn( frac ) );
}
protected override void OnUpdate()
{
base.OnUpdate();
if ( _progress < Duration )
{
_progress += Time.Delta;
var frac = _progress / Duration;
if ( frac > 0.99f )
{
Dropper.LocalPosition = EndPosition;
foreach ( var effects in Components.GetAll<PreparedEffects>( FindMode.EnabledInSelf ) )
effects.PerformEffects();
if ( DeleteObject )
GameObject.Destroy();
else
Destroy();
}
else
{
Lerp( frac );
}
}
}
}