protected override void OnDestroy() { buffer.Dispose(); if (instance?.Exists ?? false) { instance.Destroy(); } // bufferWithOffset?.Dispose(); }
public void OnKeyPress(Key key) { switch (key) { case Key.P: if (instance?.Source.State == SoundState.Paused) { instance.Source.Play(); } else { instance = buffer.Play(false, volume: 0.5, pitch: 1); } break; case Key.N: buffer.Play(true); break; case Key.O: instance = bufferWithOffset.Play(true); break; case Key.U: instance?.Source.Pause(); break; case Key.S: if (Keyboard.IsDown(Key.ShiftLeft)) { buffer.StopAll(); } else { instance?.Destroy(); instance = null; } break; } }