Files
FlowScope/Packages/com.flowscope.gamecore/Runtime/Audio/AudioHandle.cs
2026-06-04 14:54:49 +08:00

26 lines
697 B
C#

using System;
namespace FlowScope.Audio
{
public sealed class AudioHandle : IAudioHandle
{
private readonly Func<bool> _isPlaying;
private readonly Action<float> _stop;
internal AudioHandle(Func<bool> isPlaying, Action<float> stop)
{
_isPlaying = isPlaying ?? throw new ArgumentNullException(nameof(isPlaying));
_stop = stop ?? throw new ArgumentNullException(nameof(stop));
}
public bool IsPlaying => _isPlaying();
public void Stop(float fadeOut = 0f)
{
_stop(fadeOut);
}
internal static AudioHandle Stopped { get; } = new AudioHandle(() => false, _ => { });
}
}