2
2
using UnityEngine ;
3
3
using UnityEngine . Audio ;
4
4
namespace SoundSystem {
5
-
6
5
/// <summary>
7
6
/// Specifies how clips should be retrieved from a Sound
8
7
/// </summary>
@@ -26,8 +25,8 @@ public class Sound : ScriptableObject {
26
25
/// An internal array of all playable clips
27
26
/// </summary>
28
27
[ SerializeField ] private AudioClip [ ] clips ;
29
- private int clipIndex = 0 ;
30
- public int ClipIndex => clipIndex ;
28
+ private int _clipIndex = 0 ;
29
+ public int ClipIndex => _clipIndex ;
31
30
32
31
/// <summary>
33
32
/// Specifies how clips should be retrieved from this Sound
@@ -68,6 +67,10 @@ public void OnDisable() {
68
67
AudioManager . UnloadSounds ( new Sound [ ] { this } ) ;
69
68
}
70
69
70
+ public void Reset ( ) {
71
+ _clipIndex = 0 ;
72
+ }
73
+
71
74
#region ManageClips
72
75
73
76
private void LoadClips ( ) {
@@ -95,15 +98,15 @@ public AudioClip GetClip() {
95
98
96
99
switch ( clipType ) {
97
100
case ClipType . ordered :
98
- clipIndex = ( clipIndex + 1 ) % clips . Length ;
101
+ _clipIndex = ( _clipIndex + 1 ) % clips . Length ;
99
102
break ;
100
103
case ClipType . random :
101
- clipIndex = Random . Range ( 0 , clips . Length ) ;
104
+ _clipIndex = Random . Range ( 0 , clips . Length ) ;
102
105
break ;
103
106
default :
104
107
break ;
105
108
}
106
- return clips [ clipIndex ] ;
109
+ return clips [ _clipIndex ] ;
107
110
}
108
111
109
112
///<summary>
@@ -114,13 +117,13 @@ public void SetClipIndex(int index) {
114
117
Debug . LogWarning ( "Warning [Sound " + name + "] should not call setClipIndex unless ClipOrder is set to manual" ) ;
115
118
}
116
119
117
- clipIndex = index ;
120
+ _clipIndex = index ;
118
121
}
119
122
120
123
public void ManualIncrementIndex ( ) {
121
124
if ( clipType != ClipType . manual ) return ;
122
125
123
- clipIndex = ( clipIndex + 1 ) % clips . Length ;
126
+ _clipIndex = ( _clipIndex + 1 ) % clips . Length ;
124
127
}
125
128
126
129
#endregion //ManageClips
0 commit comments