Skip to content

Commit

Permalink
Remove null audio clips in inspector
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurkehrwald authored and freezy committed Jan 16, 2025
1 parent 6abd49f commit c258871
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using UnityEngine.UIElements;
using UnityEngine;
using UnityEditor.UIElements;
using System.Collections.Generic;

namespace VisualPinball.Unity.Editor
{
Expand Down Expand Up @@ -59,13 +60,24 @@ private void OnEnable()

private void OnDisable()
{
RemoveNullClips();
_instantCts.Cancel();
_instantCts.Dispose();
_instantCts = null;
_allowFadeCts.Dispose();
_allowFadeCts = null;
}

private void RemoveNullClips()
{
var clipsProp = serializedObject.FindProperty("_clips");
for (var i = clipsProp.arraySize -1; i >= 0; i--) {
if (clipsProp.GetArrayElementAtIndex(i).objectReferenceValue == null)
clipsProp.DeleteArrayElementAtIndex(i);
}
serializedObject.ApplyModifiedPropertiesWithoutUndo();
}

private async void OnPlayButtonClicked()
{
_playButton.clicked -= OnPlayButtonClicked;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ public bool IsValid()

private AudioClip GetClip()
{
_clips.ToList().RemoveAll(clip => clip == null);
if (_clips.Length == 0) {
throw new InvalidOperationException($"The sound asset '{name}' has no audio clips to play.");
}
Expand Down

0 comments on commit c258871

Please sign in to comment.