net.dreditor.audio 0.1.6 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. package/.attestation.p7m +0 -0
  2. package/ClearAudioSourceOnTitleScreen.cs +50 -50
  3. package/ClearAudioSourceOnTitleScreen.cs.meta +11 -11
  4. package/CreditsMusic.cs +63 -63
  5. package/CreditsMusic.cs.meta +11 -11
  6. package/CreditsMusicUnity.cs +21 -21
  7. package/CreditsMusicUnity.cs.meta +11 -11
  8. package/DREditor.Audio.asmdef +18 -18
  9. package/DREditor.Audio.asmdef.meta +7 -7
  10. package/EnvironmentSFXMananger.cs +159 -159
  11. package/EnvironmentSFXMananger.cs.meta +11 -11
  12. package/EnvironmentSFXManangerBase.cs +23 -23
  13. package/EnvironmentSFXManangerBase.cs.meta +11 -11
  14. package/Music.cs +26 -26
  15. package/Music.cs.meta +11 -11
  16. package/MusicFMOD.cs +31 -31
  17. package/MusicFMOD.cs.meta +11 -11
  18. package/MusicManager.cs +435 -435
  19. package/MusicManager.cs.meta +11 -11
  20. package/MusicManagerBase.cs +114 -114
  21. package/MusicManagerBase.cs.meta +11 -11
  22. package/MusicSaver.cs +126 -126
  23. package/MusicSaver.cs.meta +11 -11
  24. package/MusicTextHandler.cs +118 -118
  25. package/MusicTextHandler.cs.meta +11 -11
  26. package/OnVoiceLineSettingChanged.cs +68 -68
  27. package/OnVoiceLineSettingChanged.cs.meta +11 -11
  28. package/OptionVolume.cs +75 -75
  29. package/OptionVolume.cs.meta +11 -11
  30. package/PlaySelectAudioOnUIChange.cs +41 -41
  31. package/PlaySelectAudioOnUIChange.cs.meta +11 -11
  32. package/PlaySubmitSFXOnClick.cs +22 -22
  33. package/PlaySubmitSFXOnClick.cs.meta +11 -11
  34. package/Playlist.cs +80 -80
  35. package/Playlist.cs.meta +11 -11
  36. package/PlaylistEditor.cs +357 -357
  37. package/PlaylistEditor.cs.meta +11 -11
  38. package/PlaylistFMOD.cs +38 -38
  39. package/PlaylistFMOD.cs.meta +11 -11
  40. package/SFXManager.cs +347 -347
  41. package/SFXManager.cs.meta +11 -11
  42. package/SFXManagerBase.cs +37 -37
  43. package/SFXManagerBase.cs.meta +11 -11
  44. package/{Samples → Samples~}/Audio_Event_Save_Handler.prefab +57 -57
  45. package/{Samples → Samples~}/Audio_Event_Save_Handler.prefab.meta +7 -7
  46. package/{Samples → Samples~}/Credits_Music_Unity.prefab +66 -66
  47. package/{Samples → Samples~}/Credits_Music_Unity.prefab.meta +7 -7
  48. package/{Samples → Samples~}/Dialogue_Click_Sound_Player_DRE.prefab +76 -76
  49. package/{Samples → Samples~}/Dialogue_Click_Sound_Player_DRE.prefab.meta +7 -7
  50. package/{Samples → Samples~}/Environment_SFX_Manager.prefab +146 -146
  51. package/{Samples → Samples~}/Environment_SFX_Manager.prefab.meta +7 -7
  52. package/{Samples → Samples~}/Environment_SFX_Manager_Shell.prefab +96 -96
  53. package/{Samples → Samples~}/Environment_SFX_Manager_Shell.prefab.meta +7 -7
  54. package/{Samples → Samples~}/Environment_Source.prefab +130 -130
  55. package/{Samples → Samples~}/Environment_Source.prefab.meta +7 -7
  56. package/{Samples → Samples~}/Music_Manager.prefab +146 -146
  57. package/{Samples → Samples~}/Music_Manager.prefab.meta +7 -7
  58. package/{Samples → Samples~}/Music_Manager_Shell.prefab +75 -75
  59. package/{Samples → Samples~}/Music_Manager_Shell.prefab.meta +7 -7
  60. package/{Samples → Samples~}/Music_Source.prefab +144 -144
  61. package/{Samples → Samples~}/Music_Source.prefab.meta +7 -7
  62. package/{Samples → Samples~}/On_Voice_Line_Setting_Changed.prefab +53 -53
  63. package/{Samples → Samples~}/On_Voice_Line_Setting_Changed.prefab.meta +7 -7
  64. package/{Samples → Samples~}/Play_Select_Audio_On_UI_Change.prefab +46 -46
  65. package/{Samples → Samples~}/Play_Select_Audio_On_UI_Change.prefab.meta +7 -7
  66. package/{Samples → Samples~}/SFX_Manager.prefab +397 -397
  67. package/{Samples → Samples~}/SFX_Manager.prefab.meta +7 -7
  68. package/{Samples → Samples~}/SFX_Manager_Shell.prefab +53 -53
  69. package/{Samples → Samples~}/SFX_Manager_Shell.prefab.meta +7 -7
  70. package/{Samples → Samples~}/SFX_Source.prefab +130 -130
  71. package/{Samples → Samples~}/SFX_Source.prefab.meta +7 -7
  72. package/{Samples → Samples~}/Select_SFX_On_Setting_Changed.prefab +51 -51
  73. package/{Samples → Samples~}/Select_SFX_On_Setting_Changed.prefab.meta +7 -7
  74. package/{Samples → Samples~}/Sound_Manager.prefab +473 -473
  75. package/{Samples → Samples~}/Sound_Manager.prefab.meta +7 -7
  76. package/{Samples → Samples~}/Sound_Manager_Events.prefab +261 -261
  77. package/{Samples → Samples~}/Sound_Manager_Events.prefab.meta +7 -7
  78. package/{Samples → Samples~}/Sound_Manager_Shell.prefab +370 -370
  79. package/{Samples → Samples~}/Sound_Manager_Shell.prefab.meta +7 -7
  80. package/{Samples → Samples~}/Sound_Player_DRE.prefab +47 -47
  81. package/{Samples → Samples~}/Sound_Player_DRE.prefab.meta +7 -7
  82. package/{Samples → Samples~}/StopAllAudio.asset +14 -14
  83. package/{Samples → Samples~}/StopAllAudio.asset.meta +8 -8
  84. package/{Samples → Samples~}/UI_Cancel_Source.prefab +130 -130
  85. package/{Samples → Samples~}/UI_Cancel_Source.prefab.meta +7 -7
  86. package/{Samples → Samples~}/UI_Select_Source.prefab +130 -130
  87. package/{Samples → Samples~}/UI_Select_Source.prefab.meta +7 -7
  88. package/{Samples → Samples~}/UI_Submit_Source.prefab +130 -130
  89. package/{Samples → Samples~}/UI_Submit_Source.prefab.meta +7 -7
  90. package/{Samples → Samples~}/Voice_SFX_Manager.prefab +146 -146
  91. package/{Samples → Samples~}/Voice_SFX_Manager.prefab.meta +7 -7
  92. package/{Samples → Samples~}/Voice_SFX_Manager_Shell.prefab +49 -49
  93. package/{Samples → Samples~}/Voice_SFX_Manager_Shell.prefab.meta +7 -7
  94. package/{Samples → Samples~}/Voice_Source.prefab +130 -130
  95. package/{Samples → Samples~}/Voice_Source.prefab.meta +7 -7
  96. package/SelectSFXOnSceneEvent.cs +21 -21
  97. package/SelectSFXOnSceneEvent.cs.meta +11 -11
  98. package/SoundManager.cs +190 -190
  99. package/SoundManager.cs.meta +11 -11
  100. package/SoundManagerBase.cs +72 -72
  101. package/SoundManagerBase.cs.meta +11 -11
  102. package/SoundPlayerDRE.cs +26 -26
  103. package/SoundPlayerDRE.cs.meta +11 -11
  104. package/SoundPlayerDREUnity.cs +28 -28
  105. package/SoundPlayerDREUnity.cs.meta +11 -11
  106. package/SoundService.cs +10 -10
  107. package/SoundService.cs.meta +11 -11
  108. package/StopEnvAudioToTitle.cs +16 -16
  109. package/StopEnvAudioToTitle.cs.meta +11 -11
  110. package/VOManagerBase.cs +28 -28
  111. package/VOManagerBase.cs.meta +11 -11
  112. package/VoiceSFXManager.cs +104 -104
  113. package/VoiceSFXManager.cs.meta +11 -11
  114. package/package.json +41 -36
  115. package/package.json.meta +7 -7
  116. package/Samples.meta +0 -8
package/SFXManager.cs CHANGED
@@ -1,348 +1,348 @@
1
- //Author: Benjamin "Sweden" Jillson : Discord: sweden_gaming For Project Eden's Garden
2
- using System;
3
- using System.Collections;
4
- using System.Collections.Generic;
5
- using System.Linq;
6
- using UnityEngine;
7
- using UnityEngine.Serialization;
8
-
9
-
10
- #if FMOD_UNITY
11
- using FMODUnity;
12
- #endif
13
-
14
- namespace DREditor.Audio
15
- {
16
- /// <summary>
17
- ///
18
- /// </summary>
19
- public class SFXManager : SFXManagerBase
20
- {
21
- /// <summary>
22
- ///
23
- /// </summary>
24
- [Header("")]
25
- [Divider]
26
- [Tooltip("")]
27
- [SerializeField] bool debugLogs = false;
28
-
29
-
30
- [Header("")]
31
- [Divider]
32
- #if FMOD_UNITY
33
- /// <summary>
34
- ///
35
- /// </summary>
36
- [Tooltip("")]
37
- [SerializeField] protected StudioEventEmitter sfxSource = null;
38
- #else
39
- /// <summary>
40
- ///
41
- /// </summary>
42
- [Tooltip("")]
43
- [SerializeField] protected AudioSource sfxSource = null;
44
- #endif
45
-
46
- #if FMOD_UNITY
47
- /// <summary>
48
- ///
49
- /// </summary>
50
- [Header("")]
51
- [Divider]
52
- [FormerlySerializedAs("SubmitSource")]
53
- [Tooltip("")]
54
- [SerializeField] protected StudioEventEmitter submitSource = null;
55
-
56
- /// <summary>
57
- ///
58
- /// </summary>
59
- [FormerlySerializedAs("CancelSource")]
60
- [Tooltip("")]
61
- [SerializeField] protected StudioEventEmitter cancelSource = null;
62
-
63
- /// <summary>
64
- ///
65
- /// </summary>
66
- [FormerlySerializedAs("SelectSource")]
67
- [Tooltip("")]
68
- [SerializeField] protected StudioEventEmitter selectSource = null;
69
- #else
70
- /// <summary>
71
- ///
72
- /// </summary>
73
- [Header("")]
74
- [Divider]
75
- [FormerlySerializedAs("SubmitSource")]
76
- [Tooltip("")]
77
- [SerializeField] protected AudioSource submitSource = null;
78
-
79
- /// <summary>
80
- ///
81
- /// </summary>
82
- [FormerlySerializedAs("CancelSource")]
83
- [Tooltip("")]
84
- [SerializeField] protected AudioSource cancelSource = null;
85
-
86
- /// <summary>
87
- ///
88
- /// </summary>
89
- [FormerlySerializedAs("SelectSource")]
90
- [Tooltip("")]
91
- [SerializeField] protected AudioSource selectSource = null;
92
- #endif
93
-
94
- /// <inheritdoc/>
95
- protected override void InitializeService()
96
- {
97
- base.InitializeService();
98
- #if FMOD_UNITY
99
- if (sfxSource == null)
100
- sfxSource = GetComponentInChildren<StudioEventEmitter>();
101
- #else
102
- if (sfxSource == null)
103
- sfxSource = GetComponentInChildren<AudioSource>();
104
- #endif
105
- }
106
-
107
- /// <inheritdoc/>
108
- public override void PlaySubmit() => PlaySource(submitSource);
109
-
110
- /// <inheritdoc/>
111
- public override void PlayCancel() => PlaySource(cancelSource);
112
-
113
- /// <inheritdoc/>
114
- public override void PlaySelect() => PlaySource(selectSource);
115
-
116
-
117
- /// <inheritdoc/>
118
- public override void PlaySFX<T>(T name)
119
- {
120
- #if FMOD_UNITY
121
- if (name is string eventName)
122
- {
123
- if (eventName == "")
124
- {
125
- if (debugLogs)
126
- UnityEngine.Debug.LogWarning("ALERT: CANCELED SFX: " + eventName);
127
-
128
- return;
129
- }
130
-
131
- if (debugLogs)
132
- UnityEngine.Debug.Log("REPORT: Playing SFX: " + eventName);
133
-
134
- if (!sfxSource.IsPlaying())
135
- PlaySource(sfxSource, eventName);
136
- else
137
- PlayAdditionalSoundInstance(eventName);
138
- }
139
- #else
140
- if (name is AudioClip eventName)
141
- {
142
- if (eventName == null)
143
- {
144
- if (debugLogs)
145
- UnityEngine.Debug.LogWarning("ALERT: CANCELED SFX: " + eventName);
146
-
147
- return;
148
- }
149
-
150
- if (debugLogs)
151
- UnityEngine.Debug.Log("REPORT: Playing SFX: " + eventName);
152
-
153
- if (!sfxSource.isPlaying)
154
- PlaySource(sfxSource, eventName);
155
- else
156
- PlayAdditionalSoundInstance(eventName);
157
- }
158
- #endif
159
- }
160
-
161
- #if FMOD_UNITY
162
- /// <summary>
163
- ///
164
- /// </summary>
165
- /// <param name="eventName"></param>
166
- protected virtual void PlayAdditionalSoundInstance(string eventName)
167
- {
168
- var emitter = gameObject.AddComponent<StudioEventEmitter>();
169
-
170
- emitter.Event = eventName;
171
-
172
- emitter.TriggerOnce = true;
173
-
174
- emitter.Play();
175
-
176
- StartCoroutine(WaitForInstanceSFXToFinish(emitter));
177
- }
178
-
179
- /// <summary>
180
- ///
181
- /// </summary>
182
- /// <param name="emitter"></param>
183
- /// <returns></returns>
184
- protected virtual IEnumerator WaitForInstanceSFXToFinish(StudioEventEmitter emitter)
185
- {
186
- while (emitter.IsPlaying())
187
- yield return null;
188
-
189
- Destroy(emitter);
190
-
191
- yield break;
192
- }
193
-
194
- /// <inheritdoc/>
195
- public override void StopSoundFX()
196
- {
197
- sfxSource.Stop();
198
-
199
- StopAllInstanceEmitters();
200
- }
201
-
202
- /// <summary>
203
- ///
204
- /// </summary>
205
- protected virtual void StopAllInstanceEmitters()
206
- {
207
- AffectInstanceEmitters((emitter) => emitter.Stop());
208
-
209
- AffectInstanceEmitters((emitter) => Destroy(emitter));
210
- }
211
-
212
- /// <summary>
213
- ///
214
- /// </summary>
215
- /// <param name="affectEmitter"></param>
216
- protected virtual void AffectInstanceEmitters(Action<StudioEventEmitter> affectEmitter)
217
- {
218
- List<StudioEventEmitter> emitters = GetComponents<StudioEventEmitter>().ToList();
219
-
220
- if (emitters.Count > 0)
221
- foreach (StudioEventEmitter emitter in emitters)
222
- if (emitter != null)
223
- affectEmitter(emitter);
224
- }
225
-
226
-
227
- /// <summary>
228
- ///
229
- /// </summary>
230
- /// <param name="emitter"></param>
231
- protected virtual void PlaySource(StudioEventEmitter emitter)
232
- {
233
- if (!(emitter != null) || emitter.Event == "")
234
- return;
235
-
236
- emitter.Play();
237
- }
238
-
239
- /// <summary>
240
- ///
241
- /// </summary>
242
- /// <param name="source"></param>
243
- /// <param name="eventName"></param>
244
- protected virtual void PlaySource(StudioEventEmitter source, string eventName)
245
- {
246
- if (eventName == "" || source == null)
247
- return;
248
-
249
- source.Stop();
250
-
251
- source.Event = eventName;
252
-
253
- source.Play();
254
- }
255
- #else
256
- /// <summary>
257
- ///
258
- /// </summary>
259
- /// <param name="eventName"></param>
260
- protected virtual void PlayAdditionalSoundInstance(AudioClip eventName)
261
- {
262
- var emitter = gameObject.AddComponent<AudioSource>();
263
-
264
- emitter.clip = eventName;
265
-
266
- emitter.Play();
267
-
268
- StartCoroutine(WaitForInstanceSFXToFinish(emitter));
269
- }
270
-
271
- /// <summary>
272
- ///
273
- /// </summary>
274
- /// <param name="emitter"></param>
275
- /// <returns></returns>
276
- protected virtual IEnumerator WaitForInstanceSFXToFinish(AudioSource emitter)
277
- {
278
- while (emitter.isPlaying)
279
- yield return null;
280
-
281
- Destroy(emitter);
282
-
283
- yield break;
284
- }
285
-
286
- public override void StopSoundFX()
287
- {
288
- sfxSource.Stop();
289
-
290
- StopAllInstanceEmitters();
291
- }
292
-
293
- /// <summary>
294
- ///
295
- /// </summary>
296
- protected virtual void StopAllInstanceEmitters()
297
- {
298
- AffectInstanceEmitters((emitter) => emitter.Stop());
299
-
300
- AffectInstanceEmitters((emitter) => Destroy(emitter));
301
- }
302
-
303
- /// <summary>
304
- ///
305
- /// </summary>
306
- /// <param name="affectEmitter"></param>
307
- protected virtual void AffectInstanceEmitters(Action<AudioSource> affectEmitter)
308
- {
309
- List<AudioSource> emitters = GetComponents<AudioSource>().ToList();
310
-
311
- if (emitters.Count > 0)
312
- foreach (AudioSource emitter in emitters)
313
- if (emitter != null)
314
- affectEmitter(emitter);
315
- }
316
-
317
-
318
- /// <summary>
319
- ///
320
- /// </summary>
321
- /// <param name="source"></param>
322
- protected virtual void PlaySource(AudioSource source)
323
- {
324
- if (!(source != null) || source.clip == null)
325
- return;
326
-
327
- source.Play();
328
- }
329
-
330
- /// <summary>
331
- ///
332
- /// </summary>
333
- /// <param name="source"></param>
334
- /// <param name="clip"></param>
335
- protected virtual void PlaySource(AudioSource source, AudioClip clip)
336
- {
337
- if (clip == null || source == null)
338
- return;
339
-
340
- source.Stop();
341
-
342
- source.clip = clip;
343
-
344
- source.Play();
345
- }
346
- #endif
347
- }
1
+ //Author: Benjamin "Sweden" Jillson : Discord: sweden_gaming For Project Eden's Garden
2
+ using System;
3
+ using System.Collections;
4
+ using System.Collections.Generic;
5
+ using System.Linq;
6
+ using UnityEngine;
7
+ using UnityEngine.Serialization;
8
+
9
+
10
+ #if FMOD_UNITY
11
+ using FMODUnity;
12
+ #endif
13
+
14
+ namespace DREditor.Audio
15
+ {
16
+ /// <summary>
17
+ ///
18
+ /// </summary>
19
+ public class SFXManager : SFXManagerBase
20
+ {
21
+ /// <summary>
22
+ ///
23
+ /// </summary>
24
+ [Header("")]
25
+ [Divider]
26
+ [Tooltip("")]
27
+ [SerializeField] bool debugLogs = false;
28
+
29
+
30
+ [Header("")]
31
+ [Divider]
32
+ #if FMOD_UNITY
33
+ /// <summary>
34
+ ///
35
+ /// </summary>
36
+ [Tooltip("")]
37
+ [SerializeField] protected StudioEventEmitter sfxSource = null;
38
+ #else
39
+ /// <summary>
40
+ ///
41
+ /// </summary>
42
+ [Tooltip("")]
43
+ [SerializeField] protected AudioSource sfxSource = null;
44
+ #endif
45
+
46
+ #if FMOD_UNITY
47
+ /// <summary>
48
+ ///
49
+ /// </summary>
50
+ [Header("")]
51
+ [Divider]
52
+ [FormerlySerializedAs("SubmitSource")]
53
+ [Tooltip("")]
54
+ [SerializeField] protected StudioEventEmitter submitSource = null;
55
+
56
+ /// <summary>
57
+ ///
58
+ /// </summary>
59
+ [FormerlySerializedAs("CancelSource")]
60
+ [Tooltip("")]
61
+ [SerializeField] protected StudioEventEmitter cancelSource = null;
62
+
63
+ /// <summary>
64
+ ///
65
+ /// </summary>
66
+ [FormerlySerializedAs("SelectSource")]
67
+ [Tooltip("")]
68
+ [SerializeField] protected StudioEventEmitter selectSource = null;
69
+ #else
70
+ /// <summary>
71
+ ///
72
+ /// </summary>
73
+ [Header("")]
74
+ [Divider]
75
+ [FormerlySerializedAs("SubmitSource")]
76
+ [Tooltip("")]
77
+ [SerializeField] protected AudioSource submitSource = null;
78
+
79
+ /// <summary>
80
+ ///
81
+ /// </summary>
82
+ [FormerlySerializedAs("CancelSource")]
83
+ [Tooltip("")]
84
+ [SerializeField] protected AudioSource cancelSource = null;
85
+
86
+ /// <summary>
87
+ ///
88
+ /// </summary>
89
+ [FormerlySerializedAs("SelectSource")]
90
+ [Tooltip("")]
91
+ [SerializeField] protected AudioSource selectSource = null;
92
+ #endif
93
+
94
+ /// <inheritdoc/>
95
+ protected override void InitializeService()
96
+ {
97
+ base.InitializeService();
98
+ #if FMOD_UNITY
99
+ if (sfxSource == null)
100
+ sfxSource = GetComponentInChildren<StudioEventEmitter>();
101
+ #else
102
+ if (sfxSource == null)
103
+ sfxSource = GetComponentInChildren<AudioSource>();
104
+ #endif
105
+ }
106
+
107
+ /// <inheritdoc/>
108
+ public override void PlaySubmit() => PlaySource(submitSource);
109
+
110
+ /// <inheritdoc/>
111
+ public override void PlayCancel() => PlaySource(cancelSource);
112
+
113
+ /// <inheritdoc/>
114
+ public override void PlaySelect() => PlaySource(selectSource);
115
+
116
+
117
+ /// <inheritdoc/>
118
+ public override void PlaySFX<T>(T name)
119
+ {
120
+ #if FMOD_UNITY
121
+ if (name is string eventName)
122
+ {
123
+ if (eventName == "")
124
+ {
125
+ if (debugLogs)
126
+ UnityEngine.Debug.LogWarning("ALERT: CANCELED SFX: " + eventName);
127
+
128
+ return;
129
+ }
130
+
131
+ if (debugLogs)
132
+ UnityEngine.Debug.Log("REPORT: Playing SFX: " + eventName);
133
+
134
+ if (!sfxSource.IsPlaying())
135
+ PlaySource(sfxSource, eventName);
136
+ else
137
+ PlayAdditionalSoundInstance(eventName);
138
+ }
139
+ #else
140
+ if (name is AudioClip eventName)
141
+ {
142
+ if (eventName == null)
143
+ {
144
+ if (debugLogs)
145
+ UnityEngine.Debug.LogWarning("ALERT: CANCELED SFX: " + eventName);
146
+
147
+ return;
148
+ }
149
+
150
+ if (debugLogs)
151
+ UnityEngine.Debug.Log("REPORT: Playing SFX: " + eventName);
152
+
153
+ if (!sfxSource.isPlaying)
154
+ PlaySource(sfxSource, eventName);
155
+ else
156
+ PlayAdditionalSoundInstance(eventName);
157
+ }
158
+ #endif
159
+ }
160
+
161
+ #if FMOD_UNITY
162
+ /// <summary>
163
+ ///
164
+ /// </summary>
165
+ /// <param name="eventName"></param>
166
+ protected virtual void PlayAdditionalSoundInstance(string eventName)
167
+ {
168
+ var emitter = gameObject.AddComponent<StudioEventEmitter>();
169
+
170
+ emitter.Event = eventName;
171
+
172
+ emitter.TriggerOnce = true;
173
+
174
+ emitter.Play();
175
+
176
+ StartCoroutine(WaitForInstanceSFXToFinish(emitter));
177
+ }
178
+
179
+ /// <summary>
180
+ ///
181
+ /// </summary>
182
+ /// <param name="emitter"></param>
183
+ /// <returns></returns>
184
+ protected virtual IEnumerator WaitForInstanceSFXToFinish(StudioEventEmitter emitter)
185
+ {
186
+ while (emitter.IsPlaying())
187
+ yield return null;
188
+
189
+ Destroy(emitter);
190
+
191
+ yield break;
192
+ }
193
+
194
+ /// <inheritdoc/>
195
+ public override void StopSoundFX()
196
+ {
197
+ sfxSource.Stop();
198
+
199
+ StopAllInstanceEmitters();
200
+ }
201
+
202
+ /// <summary>
203
+ ///
204
+ /// </summary>
205
+ protected virtual void StopAllInstanceEmitters()
206
+ {
207
+ AffectInstanceEmitters((emitter) => emitter.Stop());
208
+
209
+ AffectInstanceEmitters((emitter) => Destroy(emitter));
210
+ }
211
+
212
+ /// <summary>
213
+ ///
214
+ /// </summary>
215
+ /// <param name="affectEmitter"></param>
216
+ protected virtual void AffectInstanceEmitters(Action<StudioEventEmitter> affectEmitter)
217
+ {
218
+ List<StudioEventEmitter> emitters = GetComponents<StudioEventEmitter>().ToList();
219
+
220
+ if (emitters.Count > 0)
221
+ foreach (StudioEventEmitter emitter in emitters)
222
+ if (emitter != null)
223
+ affectEmitter(emitter);
224
+ }
225
+
226
+
227
+ /// <summary>
228
+ ///
229
+ /// </summary>
230
+ /// <param name="emitter"></param>
231
+ protected virtual void PlaySource(StudioEventEmitter emitter)
232
+ {
233
+ if (!(emitter != null) || emitter.Event == "")
234
+ return;
235
+
236
+ emitter.Play();
237
+ }
238
+
239
+ /// <summary>
240
+ ///
241
+ /// </summary>
242
+ /// <param name="source"></param>
243
+ /// <param name="eventName"></param>
244
+ protected virtual void PlaySource(StudioEventEmitter source, string eventName)
245
+ {
246
+ if (eventName == "" || source == null)
247
+ return;
248
+
249
+ source.Stop();
250
+
251
+ source.Event = eventName;
252
+
253
+ source.Play();
254
+ }
255
+ #else
256
+ /// <summary>
257
+ ///
258
+ /// </summary>
259
+ /// <param name="eventName"></param>
260
+ protected virtual void PlayAdditionalSoundInstance(AudioClip eventName)
261
+ {
262
+ var emitter = gameObject.AddComponent<AudioSource>();
263
+
264
+ emitter.clip = eventName;
265
+
266
+ emitter.Play();
267
+
268
+ StartCoroutine(WaitForInstanceSFXToFinish(emitter));
269
+ }
270
+
271
+ /// <summary>
272
+ ///
273
+ /// </summary>
274
+ /// <param name="emitter"></param>
275
+ /// <returns></returns>
276
+ protected virtual IEnumerator WaitForInstanceSFXToFinish(AudioSource emitter)
277
+ {
278
+ while (emitter.isPlaying)
279
+ yield return null;
280
+
281
+ Destroy(emitter);
282
+
283
+ yield break;
284
+ }
285
+
286
+ public override void StopSoundFX()
287
+ {
288
+ sfxSource.Stop();
289
+
290
+ StopAllInstanceEmitters();
291
+ }
292
+
293
+ /// <summary>
294
+ ///
295
+ /// </summary>
296
+ protected virtual void StopAllInstanceEmitters()
297
+ {
298
+ AffectInstanceEmitters((emitter) => emitter.Stop());
299
+
300
+ AffectInstanceEmitters((emitter) => Destroy(emitter));
301
+ }
302
+
303
+ /// <summary>
304
+ ///
305
+ /// </summary>
306
+ /// <param name="affectEmitter"></param>
307
+ protected virtual void AffectInstanceEmitters(Action<AudioSource> affectEmitter)
308
+ {
309
+ List<AudioSource> emitters = GetComponents<AudioSource>().ToList();
310
+
311
+ if (emitters.Count > 0)
312
+ foreach (AudioSource emitter in emitters)
313
+ if (emitter != null)
314
+ affectEmitter(emitter);
315
+ }
316
+
317
+
318
+ /// <summary>
319
+ ///
320
+ /// </summary>
321
+ /// <param name="source"></param>
322
+ protected virtual void PlaySource(AudioSource source)
323
+ {
324
+ if (!(source != null) || source.clip == null)
325
+ return;
326
+
327
+ source.Play();
328
+ }
329
+
330
+ /// <summary>
331
+ ///
332
+ /// </summary>
333
+ /// <param name="source"></param>
334
+ /// <param name="clip"></param>
335
+ protected virtual void PlaySource(AudioSource source, AudioClip clip)
336
+ {
337
+ if (clip == null || source == null)
338
+ return;
339
+
340
+ source.Stop();
341
+
342
+ source.clip = clip;
343
+
344
+ source.Play();
345
+ }
346
+ #endif
347
+ }
348
348
  }