kakozuzo/Code/swb_base/extensions/ParticleExtensions.cs

30 lines
541 B
C#
Raw Permalink Normal View History

2024-10-30 19:01:58 +03:00
using System;
using System.Threading.Tasks;
namespace SWB.Base;
public static class ParticleExtensions
{
public static async void PlayUntilFinished( this SceneParticles particles, TaskSource source, Action<SceneParticles> OnFrame = null )
{
try
{
while ( particles.IsValid() && !particles.Finished )
{
await source.Frame();
if ( OnFrame is not null )
OnFrame( particles );
particles?.Simulate( Time.Delta );
}
}
catch ( TaskCanceledException )
{
// Do nothing.
}
particles.Delete();
}
}