net.dreditor.audio 0.1.6 → 0.1.7

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/MusicManager.cs CHANGED
@@ -1,436 +1,436 @@
1
- //Author: Benjamin "Sweden" Jillson : Discord: sweden_gaming For Project Eden's Garden
2
- using System.Collections;
3
- using UnityEngine;
4
- using DREditor.Services;
5
-
6
- #if FMOD_UNITY
7
- using FMODUnity;
8
- #endif
9
-
10
- namespace DREditor.Audio
11
- {
12
- /// <summary>
13
- ///
14
- /// </summary>
15
- [DefaultExecutionOrder(-1)]
16
- [ClassHeader(nameof(MusicManagerBase) + ", " + nameof(IToTitleScreen) +
17
- "\n\n")]
18
- public class MusicManager : MusicManagerBase, IToTitleScreen
19
- {
20
- /// <summary>
21
- ///
22
- /// </summary>
23
- [Header("")]
24
- [Divider]
25
- [Tooltip("")]
26
- [SerializeField] bool debugLogs = false;
27
-
28
- #if FMOD_UNITY
29
- /// <summary>
30
- ///
31
- /// </summary>
32
- [Tooltip("")]
33
- [SerializeField] protected string LastPlayedMusic = "";
34
- #else
35
- /// <summary>
36
- ///
37
- /// </summary>
38
- [Tooltip("")]
39
- [SerializeField] protected AudioClip LastPlayedMusic = null;
40
- #endif
41
- /// <summary>
42
- ///
43
- /// </summary>
44
- [Header("")]
45
- [Divider]
46
- #if FMOD_UNITY
47
- [Tooltip("")]
48
- [SerializeField] protected PlaylistFMOD jukeBox = null;
49
- #else
50
- /// <summary>
51
- ///
52
- /// </summary>
53
- [Tooltip("")]
54
- [SerializeField] protected Playlist jukeBox = null;
55
- #endif
56
- /// <summary>
57
- ///
58
- /// </summary>
59
- [Header("")]
60
- [Divider]
61
- #if FMOD_UNITY
62
- [Tooltip("")]
63
- [SerializeField] protected StudioEventEmitter musicSource = null;
64
- #else
65
- /// <summary>
66
- ///
67
- /// </summary>
68
- [Tooltip("")]
69
- [SerializeField] protected AudioSource musicSource = null;
70
- #endif
71
-
72
- /// <summary>
73
- ///
74
- /// </summary>
75
- [Header("")]
76
- [Divider]
77
- [Tooltip("")]
78
- [SerializeField] protected bool playOnStart = false;
79
- #if FMOD_UNITY
80
- /// <summary>
81
- ///
82
- /// </summary>
83
- [Tooltip("")]
84
- [EventRef][SerializeField] string startMusic = "";
85
-
86
- /// <summary>
87
- ///
88
- /// </summary>
89
- [Tooltip("")]
90
- [SerializeField] protected string stopMusicCode = "Null";
91
- #else
92
- /// <summary>
93
- ///
94
- /// </summary>
95
- [Tooltip("")]
96
- [SerializeField] protected AudioClip startMusic = null;
97
-
98
-
99
- /// <summary>
100
- ///
101
- /// </summary>
102
- protected bool fading = false;
103
- #endif
104
-
105
-
106
- /// <inheritdoc/>
107
- protected override void InitializeService()
108
- {
109
- base.InitializeService();
110
-
111
- if (musicSource == null)
112
- #if FMOD_UNITY
113
- musicSource = GetComponentInChildren<StudioEventEmitter>();
114
- #else
115
- musicSource = GetComponentInChildren<AudioSource>();
116
- #endif
117
- }
118
-
119
-
120
- /// <summary>
121
- ///
122
- /// </summary>
123
- protected virtual void Start()
124
- {
125
- if (playOnStart)
126
- #if FMOD_UNITY
127
- StartCoroutine(PlayMusicOnStartRoutine());
128
- #else
129
- PlayMusic(startMusic);
130
- #endif
131
- }
132
- #if FMOD_UNITY
133
- /// <summary>
134
- ///
135
- /// </summary>
136
- /// <returns></returns>
137
- protected virtual IEnumerator PlayMusicOnStartRoutine()
138
- {
139
- yield return new WaitUntil(() => RuntimeManager.IsInitialized);
140
-
141
- PlayMusic(startMusic);
142
- }
143
- #endif
144
-
145
- #if FMOD_UNITY
146
- /// <inheritdoc/>
147
- public override void PlayMusic<T>(T name, bool skip = false)
148
- {
149
- if (name is string eventName)
150
- if (musicSource != null && musicSource.Event == eventName)
151
- return;
152
- else if (eventName == "" || eventName == stopMusicCode)
153
- OnPlayedInvalidMusic();
154
- else
155
- PlayValidMusic(eventName, skip);
156
- }
157
-
158
- /// <inheritdoc/>
159
- public override bool MusicIsPlaying() => musicSource != null && musicSource.IsPlaying();
160
- #else
161
- public override void PlayMusic<T>(T name, bool skip = false)
162
- {
163
- if (name is string clipName && !string.IsNullOrEmpty(clipName))
164
- PlayValidMusic(jukeBox.GetAudioClip(clipName), skip);
165
-
166
- if (name is AudioClip eventName)
167
- if (musicSource != null && musicSource.clip == eventName)
168
- return;
169
- else if (eventName == null)
170
- OnPlayedInvalidMusic();
171
- else
172
- PlayValidMusic(eventName, skip);
173
- }
174
-
175
- public override bool MusicIsPlaying() => musicSource.isPlaying;
176
- #endif
177
-
178
- /// <inheritdoc/>
179
- public override void StopPlayingMusic() => OnPlayedInvalidMusic();
180
-
181
- /// <summary>
182
- ///
183
- /// </summary>
184
- protected virtual void OnPlayedInvalidMusic()
185
- {
186
- if (musicSource != null)
187
- musicSource.Stop();
188
-
189
- ClearMusicText.Raise();
190
-
191
- ResetLastPlayedMusic();
192
- }
193
- #if FMOD_UNITY
194
- /// <summary>
195
- ///
196
- /// </summary>
197
- /// <param name="eventName"></param>
198
- /// <param name="skip"></param>
199
- public virtual void PlayValidMusic(string eventName, bool skip = false)
200
- {
201
- /* Kill/Cure FMOD NOTE
202
- *
203
- * Issue: Okay idk what the fuck happened, for whatever reason, the first music always works,
204
- * but trying to change the music like normal just ends up playing the first one, so I
205
- * had to destroy the component and add a new one just so it would work.
206
- * This is a terrible way of doing this and I have no idea whats going on. EG never had this issue
207
- * so my assumption is that the issue is internal to FMOD
208
- * SOLUTION: IT WAS FMOD, Go to StudioEventEmitter.cs on play function add this below the clear cache:
209
- * if(hasTriggered)
210
- {
211
- Lookup();
212
- }
213
- * */
214
-
215
- if (jukeBox != null)
216
- SetMusicText.SetValue(jukeBox.GetTitleFromClip(eventName));
217
-
218
- PlaySource(musicSource, eventName);
219
-
220
- if (!skip)
221
- LastPlayedMusic = eventName;
222
-
223
- StartCoroutine(WaitForUpdate());
224
-
225
- if (debugLogs && jukeBox != null)
226
- UnityEngine.Debug.LogWarning("REPORT: PLAYING Music: " + jukeBox.GetTitleFromClip(eventName) + " " + eventName);
227
- }
228
-
229
- /// <summary>
230
- ///
231
- /// </summary>
232
- /// <returns></returns>
233
- protected virtual IEnumerator WaitForUpdate()
234
- {
235
- if (musicSource == null)
236
- yield break;
237
-
238
- yield return new WaitUntil(() => RuntimeManager.IsInitialized);
239
-
240
- yield return new WaitUntil(() => musicSource.IsPlaying());
241
-
242
- InvokeMusicChange(musicSource);
243
- }
244
- #else
245
- /// <summary>
246
- ///
247
- /// </summary>
248
- /// <param name="clip"></param>
249
- /// <param name="skip"></param>
250
- protected virtual void PlayValidMusic(AudioClip clip, bool skip = false)
251
- {
252
- if (fading)
253
- fading = false;
254
-
255
- SetCurrentlyPlayingMusicText(clip);
256
-
257
- PlaySource(musicSource, clip);
258
-
259
- if (!skip)
260
- LastPlayedMusic = clip;
261
-
262
- InvokeMusicChange(musicSource);
263
-
264
- if (debugLogs && jukeBox != null)
265
- UnityEngine.Debug.LogWarning("REPORT: PLAYING Music: " + jukeBox.GetTitleFromClip(clip) + " " + clip);
266
- }
267
-
268
- /// <summary>
269
- ///
270
- /// </summary>
271
- /// <param name="clip"></param>
272
- protected virtual void SetCurrentlyPlayingMusicText(AudioClip clip)
273
- {
274
- if (jukeBox != null)
275
- SetMusicText.SetValue(jukeBox.GetTitleFromClip(clip));
276
- }
277
- #endif
278
- /// <inheritdoc/>
279
- public override void StopMusic()
280
- {
281
- ClearMusicText.Raise();
282
-
283
- if (musicSource != null)
284
- musicSource.Stop();
285
- }
286
-
287
- /// <inheritdoc/>
288
- public override void StopSound() => StopMusic();
289
-
290
- /// <inheritdoc/>
291
- public override void PlayLastMusic() => PlayMusic(LastPlayedMusic);
292
-
293
- /// <inheritdoc/>
294
- protected override void ResetLastPlayedMusic()
295
- {
296
- #if FMOD_UNITY
297
- if (musicSource != null)
298
- musicSource.Event = null;
299
- #else
300
- if (musicSource != null)
301
- musicSource.clip = null;
302
- #endif
303
- LastPlayedMusic = null;
304
- }
305
-
306
- #if FMOD_UNITY
307
- /// <summary>
308
- ///
309
- /// </summary>
310
- /// <param name="FadeTime"></param>
311
- /// <remarks></remarks>
312
- public override void FadeMusic(float FadeTime) => StopMusic();
313
- #else
314
- /// <inheritdoc/>
315
- public override void FadeMusic(float FadeTime) => StartCoroutine(FadeOut(musicSource, FadeTime));
316
-
317
- /// <summary>
318
- ///
319
- /// </summary>
320
- /// <typeparam name="T"></typeparam>
321
- /// <param name="source"></param>
322
- /// <param name="duration"></param>
323
- /// <returns></returns>
324
- protected virtual IEnumerator FadeOut<T>(T source, float duration)
325
- {
326
- fading = true;
327
-
328
- if (source is AudioSource audioSource)
329
- {
330
- float startVolume = audioSource.volume;
331
-
332
- float time = 0f;
333
-
334
- while (time < duration && fading)
335
- {
336
- audioSource.volume = Mathf.Lerp(startVolume, 0f, time / duration);
337
-
338
- time += Time.deltaTime;
339
-
340
- yield return null;
341
- }
342
-
343
- audioSource.volume = 0f;
344
-
345
- audioSource.Stop();
346
-
347
- yield return null;
348
-
349
- audioSource.volume = startVolume;
350
- }
351
-
352
- fading = false;
353
-
354
- yield break;
355
- }
356
- #endif
357
-
358
- /// <inheritdoc/>
359
- public override string GetLastPlayedMusic()
360
- {
361
- #if FMOD_UNITY
362
- return LastPlayedMusic;
363
- #else
364
- return LastPlayedMusic.name;
365
- #endif
366
- }
367
-
368
- /// <summary>
369
- ///
370
- /// </summary>
371
- public virtual void OnLoadedMusicMissing()
372
- {
373
- if (debugLogs)
374
- UnityEngine.Debug.LogWarning("ALERT: Couldn't find Saved Music, no music playing");
375
-
376
- ResetMusicText.Raise();
377
-
378
- ResetLastPlayedMusic();
379
-
380
- InvokeMusicChange(null);
381
- }
382
- #if FMOD_UNITY
383
- /// <summary>
384
- ///
385
- /// </summary>
386
- /// <param name="source"></param>
387
- /// <param name="eventName"></param>
388
- protected virtual void PlaySource(StudioEventEmitter source, string eventName)
389
- {
390
- if (eventName == "" || source == null || !EventExists(eventName))
391
- return;
392
-
393
- source.Stop();
394
-
395
- source.Event = eventName;
396
-
397
- source.Play();
398
- }
399
-
400
- /// <summary>
401
- ///
402
- /// </summary>
403
- /// <param name="path"></param>
404
- /// <returns></returns>
405
- protected virtual bool EventExists(string path)
406
- {
407
- bool result = FMODUnity.RuntimeManager.StudioSystem.getEvent(path, out _) == FMOD.RESULT.OK;
408
-
409
- if (!result)
410
- UnityEngine.Debug.LogWarning($"ALERT: The path: {path} does not match an existing event!");
411
-
412
- return result;
413
- }
414
- #else
415
- /// <summary>
416
- ///
417
- /// </summary>
418
- /// <param name="source"></param>
419
- /// <param name="clip"></param>
420
- protected virtual void PlaySource(AudioSource source, AudioClip clip)
421
- {
422
- if (clip == null)
423
- return;
424
-
425
- source.Stop();
426
-
427
- source.clip = clip;
428
-
429
- source.Play();
430
- }
431
- #endif
432
-
433
- /// <inheritdoc/>
434
- public virtual void ToTitleScreen() => StopMusic();
435
- }
1
+ //Author: Benjamin "Sweden" Jillson : Discord: sweden_gaming For Project Eden's Garden
2
+ using System.Collections;
3
+ using UnityEngine;
4
+ using DREditor.Services;
5
+
6
+ #if FMOD_UNITY
7
+ using FMODUnity;
8
+ #endif
9
+
10
+ namespace DREditor.Audio
11
+ {
12
+ /// <summary>
13
+ ///
14
+ /// </summary>
15
+ [DefaultExecutionOrder(-1)]
16
+ [ClassHeader(nameof(MusicManagerBase) + ", " + nameof(IToTitleScreen) +
17
+ "\n\n")]
18
+ public class MusicManager : MusicManagerBase, IToTitleScreen
19
+ {
20
+ /// <summary>
21
+ ///
22
+ /// </summary>
23
+ [Header("")]
24
+ [Divider]
25
+ [Tooltip("")]
26
+ [SerializeField] bool debugLogs = false;
27
+
28
+ #if FMOD_UNITY
29
+ /// <summary>
30
+ ///
31
+ /// </summary>
32
+ [Tooltip("")]
33
+ [SerializeField] protected string LastPlayedMusic = "";
34
+ #else
35
+ /// <summary>
36
+ ///
37
+ /// </summary>
38
+ [Tooltip("")]
39
+ [SerializeField] protected AudioClip LastPlayedMusic = null;
40
+ #endif
41
+ /// <summary>
42
+ ///
43
+ /// </summary>
44
+ [Header("")]
45
+ [Divider]
46
+ #if FMOD_UNITY
47
+ [Tooltip("")]
48
+ [SerializeField] protected PlaylistFMOD jukeBox = null;
49
+ #else
50
+ /// <summary>
51
+ ///
52
+ /// </summary>
53
+ [Tooltip("")]
54
+ [SerializeField] protected Playlist jukeBox = null;
55
+ #endif
56
+ /// <summary>
57
+ ///
58
+ /// </summary>
59
+ [Header("")]
60
+ [Divider]
61
+ #if FMOD_UNITY
62
+ [Tooltip("")]
63
+ [SerializeField] protected StudioEventEmitter musicSource = null;
64
+ #else
65
+ /// <summary>
66
+ ///
67
+ /// </summary>
68
+ [Tooltip("")]
69
+ [SerializeField] protected AudioSource musicSource = null;
70
+ #endif
71
+
72
+ /// <summary>
73
+ ///
74
+ /// </summary>
75
+ [Header("")]
76
+ [Divider]
77
+ [Tooltip("")]
78
+ [SerializeField] protected bool playOnStart = false;
79
+ #if FMOD_UNITY
80
+ /// <summary>
81
+ ///
82
+ /// </summary>
83
+ [Tooltip("")]
84
+ [EventRef][SerializeField] string startMusic = "";
85
+
86
+ /// <summary>
87
+ ///
88
+ /// </summary>
89
+ [Tooltip("")]
90
+ [SerializeField] protected string stopMusicCode = "Null";
91
+ #else
92
+ /// <summary>
93
+ ///
94
+ /// </summary>
95
+ [Tooltip("")]
96
+ [SerializeField] protected AudioClip startMusic = null;
97
+
98
+
99
+ /// <summary>
100
+ ///
101
+ /// </summary>
102
+ protected bool fading = false;
103
+ #endif
104
+
105
+
106
+ /// <inheritdoc/>
107
+ protected override void InitializeService()
108
+ {
109
+ base.InitializeService();
110
+
111
+ if (musicSource == null)
112
+ #if FMOD_UNITY
113
+ musicSource = GetComponentInChildren<StudioEventEmitter>();
114
+ #else
115
+ musicSource = GetComponentInChildren<AudioSource>();
116
+ #endif
117
+ }
118
+
119
+
120
+ /// <summary>
121
+ ///
122
+ /// </summary>
123
+ protected virtual void Start()
124
+ {
125
+ if (playOnStart)
126
+ #if FMOD_UNITY
127
+ StartCoroutine(PlayMusicOnStartRoutine());
128
+ #else
129
+ PlayMusic(startMusic);
130
+ #endif
131
+ }
132
+ #if FMOD_UNITY
133
+ /// <summary>
134
+ ///
135
+ /// </summary>
136
+ /// <returns></returns>
137
+ protected virtual IEnumerator PlayMusicOnStartRoutine()
138
+ {
139
+ yield return new WaitUntil(() => RuntimeManager.IsInitialized);
140
+
141
+ PlayMusic(startMusic);
142
+ }
143
+ #endif
144
+
145
+ #if FMOD_UNITY
146
+ /// <inheritdoc/>
147
+ public override void PlayMusic<T>(T name, bool skip = false)
148
+ {
149
+ if (name is string eventName)
150
+ if (musicSource != null && musicSource.Event == eventName)
151
+ return;
152
+ else if (eventName == "" || eventName == stopMusicCode)
153
+ OnPlayedInvalidMusic();
154
+ else
155
+ PlayValidMusic(eventName, skip);
156
+ }
157
+
158
+ /// <inheritdoc/>
159
+ public override bool MusicIsPlaying() => musicSource != null && musicSource.IsPlaying();
160
+ #else
161
+ public override void PlayMusic<T>(T name, bool skip = false)
162
+ {
163
+ if (name is string clipName && !string.IsNullOrEmpty(clipName))
164
+ PlayValidMusic(jukeBox.GetAudioClip(clipName), skip);
165
+
166
+ if (name is AudioClip eventName)
167
+ if (musicSource != null && musicSource.clip == eventName)
168
+ return;
169
+ else if (eventName == null)
170
+ OnPlayedInvalidMusic();
171
+ else
172
+ PlayValidMusic(eventName, skip);
173
+ }
174
+
175
+ public override bool MusicIsPlaying() => musicSource.isPlaying;
176
+ #endif
177
+
178
+ /// <inheritdoc/>
179
+ public override void StopPlayingMusic() => OnPlayedInvalidMusic();
180
+
181
+ /// <summary>
182
+ ///
183
+ /// </summary>
184
+ protected virtual void OnPlayedInvalidMusic()
185
+ {
186
+ if (musicSource != null)
187
+ musicSource.Stop();
188
+
189
+ ClearMusicText.Raise();
190
+
191
+ ResetLastPlayedMusic();
192
+ }
193
+ #if FMOD_UNITY
194
+ /// <summary>
195
+ ///
196
+ /// </summary>
197
+ /// <param name="eventName"></param>
198
+ /// <param name="skip"></param>
199
+ public virtual void PlayValidMusic(string eventName, bool skip = false)
200
+ {
201
+ /* Kill/Cure FMOD NOTE
202
+ *
203
+ * Issue: Okay idk what the fuck happened, for whatever reason, the first music always works,
204
+ * but trying to change the music like normal just ends up playing the first one, so I
205
+ * had to destroy the component and add a new one just so it would work.
206
+ * This is a terrible way of doing this and I have no idea whats going on. EG never had this issue
207
+ * so my assumption is that the issue is internal to FMOD
208
+ * SOLUTION: IT WAS FMOD, Go to StudioEventEmitter.cs on play function add this below the clear cache:
209
+ * if(hasTriggered)
210
+ {
211
+ Lookup();
212
+ }
213
+ * */
214
+
215
+ if (jukeBox != null)
216
+ SetMusicText.SetValue(jukeBox.GetTitleFromClip(eventName));
217
+
218
+ PlaySource(musicSource, eventName);
219
+
220
+ if (!skip)
221
+ LastPlayedMusic = eventName;
222
+
223
+ StartCoroutine(WaitForUpdate());
224
+
225
+ if (debugLogs && jukeBox != null)
226
+ UnityEngine.Debug.LogWarning("REPORT: PLAYING Music: " + jukeBox.GetTitleFromClip(eventName) + " " + eventName);
227
+ }
228
+
229
+ /// <summary>
230
+ ///
231
+ /// </summary>
232
+ /// <returns></returns>
233
+ protected virtual IEnumerator WaitForUpdate()
234
+ {
235
+ if (musicSource == null)
236
+ yield break;
237
+
238
+ yield return new WaitUntil(() => RuntimeManager.IsInitialized);
239
+
240
+ yield return new WaitUntil(() => musicSource.IsPlaying());
241
+
242
+ InvokeMusicChange(musicSource);
243
+ }
244
+ #else
245
+ /// <summary>
246
+ ///
247
+ /// </summary>
248
+ /// <param name="clip"></param>
249
+ /// <param name="skip"></param>
250
+ protected virtual void PlayValidMusic(AudioClip clip, bool skip = false)
251
+ {
252
+ if (fading)
253
+ fading = false;
254
+
255
+ SetCurrentlyPlayingMusicText(clip);
256
+
257
+ PlaySource(musicSource, clip);
258
+
259
+ if (!skip)
260
+ LastPlayedMusic = clip;
261
+
262
+ InvokeMusicChange(musicSource);
263
+
264
+ if (debugLogs && jukeBox != null)
265
+ UnityEngine.Debug.LogWarning("REPORT: PLAYING Music: " + jukeBox.GetTitleFromClip(clip) + " " + clip);
266
+ }
267
+
268
+ /// <summary>
269
+ ///
270
+ /// </summary>
271
+ /// <param name="clip"></param>
272
+ protected virtual void SetCurrentlyPlayingMusicText(AudioClip clip)
273
+ {
274
+ if (jukeBox != null)
275
+ SetMusicText.SetValue(jukeBox.GetTitleFromClip(clip));
276
+ }
277
+ #endif
278
+ /// <inheritdoc/>
279
+ public override void StopMusic()
280
+ {
281
+ ClearMusicText.Raise();
282
+
283
+ if (musicSource != null)
284
+ musicSource.Stop();
285
+ }
286
+
287
+ /// <inheritdoc/>
288
+ public override void StopSound() => StopMusic();
289
+
290
+ /// <inheritdoc/>
291
+ public override void PlayLastMusic() => PlayMusic(LastPlayedMusic);
292
+
293
+ /// <inheritdoc/>
294
+ protected override void ResetLastPlayedMusic()
295
+ {
296
+ #if FMOD_UNITY
297
+ if (musicSource != null)
298
+ musicSource.Event = null;
299
+ #else
300
+ if (musicSource != null)
301
+ musicSource.clip = null;
302
+ #endif
303
+ LastPlayedMusic = null;
304
+ }
305
+
306
+ #if FMOD_UNITY
307
+ /// <summary>
308
+ ///
309
+ /// </summary>
310
+ /// <param name="FadeTime"></param>
311
+ /// <remarks></remarks>
312
+ public override void FadeMusic(float FadeTime) => StopMusic();
313
+ #else
314
+ /// <inheritdoc/>
315
+ public override void FadeMusic(float FadeTime) => StartCoroutine(FadeOut(musicSource, FadeTime));
316
+
317
+ /// <summary>
318
+ ///
319
+ /// </summary>
320
+ /// <typeparam name="T"></typeparam>
321
+ /// <param name="source"></param>
322
+ /// <param name="duration"></param>
323
+ /// <returns></returns>
324
+ protected virtual IEnumerator FadeOut<T>(T source, float duration)
325
+ {
326
+ fading = true;
327
+
328
+ if (source is AudioSource audioSource)
329
+ {
330
+ float startVolume = audioSource.volume;
331
+
332
+ float time = 0f;
333
+
334
+ while (time < duration && fading)
335
+ {
336
+ audioSource.volume = Mathf.Lerp(startVolume, 0f, time / duration);
337
+
338
+ time += Time.deltaTime;
339
+
340
+ yield return null;
341
+ }
342
+
343
+ audioSource.volume = 0f;
344
+
345
+ audioSource.Stop();
346
+
347
+ yield return null;
348
+
349
+ audioSource.volume = startVolume;
350
+ }
351
+
352
+ fading = false;
353
+
354
+ yield break;
355
+ }
356
+ #endif
357
+
358
+ /// <inheritdoc/>
359
+ public override string GetLastPlayedMusic()
360
+ {
361
+ #if FMOD_UNITY
362
+ return LastPlayedMusic;
363
+ #else
364
+ return LastPlayedMusic.name;
365
+ #endif
366
+ }
367
+
368
+ /// <summary>
369
+ ///
370
+ /// </summary>
371
+ public virtual void OnLoadedMusicMissing()
372
+ {
373
+ if (debugLogs)
374
+ UnityEngine.Debug.LogWarning("ALERT: Couldn't find Saved Music, no music playing");
375
+
376
+ ResetMusicText.Raise();
377
+
378
+ ResetLastPlayedMusic();
379
+
380
+ InvokeMusicChange(null);
381
+ }
382
+ #if FMOD_UNITY
383
+ /// <summary>
384
+ ///
385
+ /// </summary>
386
+ /// <param name="source"></param>
387
+ /// <param name="eventName"></param>
388
+ protected virtual void PlaySource(StudioEventEmitter source, string eventName)
389
+ {
390
+ if (eventName == "" || source == null || !EventExists(eventName))
391
+ return;
392
+
393
+ source.Stop();
394
+
395
+ source.Event = eventName;
396
+
397
+ source.Play();
398
+ }
399
+
400
+ /// <summary>
401
+ ///
402
+ /// </summary>
403
+ /// <param name="path"></param>
404
+ /// <returns></returns>
405
+ protected virtual bool EventExists(string path)
406
+ {
407
+ bool result = FMODUnity.RuntimeManager.StudioSystem.getEvent(path, out _) == FMOD.RESULT.OK;
408
+
409
+ if (!result)
410
+ UnityEngine.Debug.LogWarning($"ALERT: The path: {path} does not match an existing event!");
411
+
412
+ return result;
413
+ }
414
+ #else
415
+ /// <summary>
416
+ ///
417
+ /// </summary>
418
+ /// <param name="source"></param>
419
+ /// <param name="clip"></param>
420
+ protected virtual void PlaySource(AudioSource source, AudioClip clip)
421
+ {
422
+ if (clip == null)
423
+ return;
424
+
425
+ source.Stop();
426
+
427
+ source.clip = clip;
428
+
429
+ source.Play();
430
+ }
431
+ #endif
432
+
433
+ /// <inheritdoc/>
434
+ public virtual void ToTitleScreen() => StopMusic();
435
+ }
436
436
  }