private void Cleanup()
 {
     _wavData = null;
     if (_wavClipEditor != null)
     {
         DestroyImmediate(_wavClipEditor);
     }
 }
        private void DrawLoadGUI()
        {
            using (new EditorGUILayout.HorizontalScope())
            {
                var oldClip = _wavClip;
                _wavClip = EditorGUILayout.ObjectField("Wav File", _wavClip, typeof(AudioClip),
                                                       false) as AudioClip;

                if (oldClip != null && _wavClip != null && oldClip != _wavClip)
                {
                    // Make sure to clean the stream up since we're loading another file
                    Cleanup();
                }

                using (new EditorGUI.DisabledScope(
                           _wavClip == null || !AssetDatabase.GetAssetPath(_wavClip).ToLower().EndsWith(".wav")))
                {
                    if (GUILayout.Button("Load", GUILayout.Width(70)))
                    {
                        try
                        {
                            // ReSharper disable once PossibleNullReferenceException
                            _wavData = new WavData(AssetDatabase.GetAssetPath(_wavClip), _wavClip.samples);
                        }
                        catch (Exception e)
                        {
                            EditorUtility.DisplayDialog("Error", $"Error while loading file: {e.Message}", "OK");
                            Cleanup();
                        }
                        finally
                        {
                            EditorUtility.ClearProgressBar();
                        }
                    }
                }
            }
        }