Skip to content

Commit 12b722a

Browse files
committed
Reset Sound after preview
1 parent c81a455 commit 12b722a

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

Editor/SoundEditor.cs

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ private void OnEnable() {
2525
}
2626

2727
private void OnDisable() {
28+
_targetSound.Reset();
2829
DestroyImmediate(_previewer.gameObject);
2930
}
3031

Runtime/Sound.cs

+11-8
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using UnityEngine;
33
using UnityEngine.Audio;
44
namespace SoundSystem {
5-
65
/// <summary>
76
/// Specifies how clips should be retrieved from a Sound
87
/// </summary>
@@ -26,8 +25,8 @@ public class Sound : ScriptableObject {
2625
/// An internal array of all playable clips
2726
/// </summary>
2827
[SerializeField] private AudioClip[] clips;
29-
private int clipIndex = 0;
30-
public int ClipIndex => clipIndex;
28+
private int _clipIndex = 0;
29+
public int ClipIndex => _clipIndex;
3130

3231
/// <summary>
3332
/// Specifies how clips should be retrieved from this Sound
@@ -68,6 +67,10 @@ public void OnDisable() {
6867
AudioManager.UnloadSounds(new Sound[] { this });
6968
}
7069

70+
public void Reset() {
71+
_clipIndex = 0;
72+
}
73+
7174
#region ManageClips
7275

7376
private void LoadClips() {
@@ -95,15 +98,15 @@ public AudioClip GetClip() {
9598

9699
switch (clipType) {
97100
case ClipType.ordered:
98-
clipIndex = (clipIndex + 1) % clips.Length;
101+
_clipIndex = (_clipIndex + 1) % clips.Length;
99102
break;
100103
case ClipType.random:
101-
clipIndex = Random.Range(0, clips.Length);
104+
_clipIndex = Random.Range(0, clips.Length);
102105
break;
103106
default:
104107
break;
105108
}
106-
return clips[clipIndex];
109+
return clips[_clipIndex];
107110
}
108111

109112
///<summary>
@@ -114,13 +117,13 @@ public void SetClipIndex(int index) {
114117
Debug.LogWarning("Warning [Sound " + name + "] should not call setClipIndex unless ClipOrder is set to manual");
115118
}
116119

117-
clipIndex = index;
120+
_clipIndex = index;
118121
}
119122

120123
public void ManualIncrementIndex() {
121124
if (clipType != ClipType.manual) return;
122125

123-
clipIndex = (clipIndex + 1) % clips.Length;
126+
_clipIndex = (_clipIndex + 1) % clips.Length;
124127
}
125128

126129
#endregion //ManageClips

0 commit comments

Comments
 (0)