net.dreditor.audio 0.0.0-stage → 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 +51 -0
  3. package/ClearAudioSourceOnTitleScreen.cs.meta +11 -0
  4. package/CreditsMusic.cs +64 -0
  5. package/CreditsMusic.cs.meta +11 -0
  6. package/CreditsMusicUnity.cs +22 -0
  7. package/CreditsMusicUnity.cs.meta +11 -0
  8. package/DREditor.Audio.asmdef +19 -0
  9. package/DREditor.Audio.asmdef.meta +7 -0
  10. package/EnvironmentSFXMananger.cs +160 -0
  11. package/EnvironmentSFXMananger.cs.meta +11 -0
  12. package/EnvironmentSFXManangerBase.cs +24 -0
  13. package/EnvironmentSFXManangerBase.cs.meta +11 -0
  14. package/Music.cs +27 -0
  15. package/Music.cs.meta +11 -0
  16. package/MusicFMOD.cs +32 -0
  17. package/MusicFMOD.cs.meta +11 -0
  18. package/MusicManager.cs +436 -0
  19. package/MusicManager.cs.meta +11 -0
  20. package/MusicManagerBase.cs +115 -0
  21. package/MusicManagerBase.cs.meta +11 -0
  22. package/MusicSaver.cs +127 -0
  23. package/MusicSaver.cs.meta +11 -0
  24. package/MusicTextHandler.cs +119 -0
  25. package/MusicTextHandler.cs.meta +11 -0
  26. package/OnVoiceLineSettingChanged.cs +69 -0
  27. package/OnVoiceLineSettingChanged.cs.meta +11 -0
  28. package/OptionVolume.cs +76 -0
  29. package/OptionVolume.cs.meta +11 -0
  30. package/PlaySelectAudioOnUIChange.cs +42 -0
  31. package/PlaySelectAudioOnUIChange.cs.meta +11 -0
  32. package/PlaySubmitSFXOnClick.cs +23 -0
  33. package/PlaySubmitSFXOnClick.cs.meta +11 -0
  34. package/Playlist.cs +81 -0
  35. package/Playlist.cs.meta +11 -0
  36. package/PlaylistEditor.cs +358 -0
  37. package/PlaylistEditor.cs.meta +11 -0
  38. package/PlaylistFMOD.cs +39 -0
  39. package/PlaylistFMOD.cs.meta +11 -0
  40. package/SFXManager.cs +348 -0
  41. package/SFXManager.cs.meta +11 -0
  42. package/SFXManagerBase.cs +38 -0
  43. package/SFXManagerBase.cs.meta +11 -0
  44. package/Samples~/Audio_Event_Save_Handler.prefab +57 -0
  45. package/Samples~/Audio_Event_Save_Handler.prefab.meta +7 -0
  46. package/Samples~/Credits_Music_Unity.prefab +66 -0
  47. package/Samples~/Credits_Music_Unity.prefab.meta +7 -0
  48. package/Samples~/Dialogue_Click_Sound_Player_DRE.prefab +76 -0
  49. package/Samples~/Dialogue_Click_Sound_Player_DRE.prefab.meta +7 -0
  50. package/Samples~/Environment_SFX_Manager.prefab +146 -0
  51. package/Samples~/Environment_SFX_Manager.prefab.meta +7 -0
  52. package/Samples~/Environment_SFX_Manager_Shell.prefab +96 -0
  53. package/Samples~/Environment_SFX_Manager_Shell.prefab.meta +7 -0
  54. package/Samples~/Environment_Source.prefab +130 -0
  55. package/Samples~/Environment_Source.prefab.meta +7 -0
  56. package/Samples~/Music_Manager.prefab +146 -0
  57. package/Samples~/Music_Manager.prefab.meta +7 -0
  58. package/Samples~/Music_Manager_Shell.prefab +75 -0
  59. package/Samples~/Music_Manager_Shell.prefab.meta +7 -0
  60. package/Samples~/Music_Source.prefab +144 -0
  61. package/Samples~/Music_Source.prefab.meta +7 -0
  62. package/Samples~/On_Voice_Line_Setting_Changed.prefab +53 -0
  63. package/Samples~/On_Voice_Line_Setting_Changed.prefab.meta +7 -0
  64. package/Samples~/Play_Select_Audio_On_UI_Change.prefab +46 -0
  65. package/Samples~/Play_Select_Audio_On_UI_Change.prefab.meta +7 -0
  66. package/Samples~/SFX_Manager.prefab +397 -0
  67. package/Samples~/SFX_Manager.prefab.meta +7 -0
  68. package/Samples~/SFX_Manager_Shell.prefab +53 -0
  69. package/Samples~/SFX_Manager_Shell.prefab.meta +7 -0
  70. package/Samples~/SFX_Source.prefab +130 -0
  71. package/Samples~/SFX_Source.prefab.meta +7 -0
  72. package/Samples~/Select_SFX_On_Setting_Changed.prefab +51 -0
  73. package/Samples~/Select_SFX_On_Setting_Changed.prefab.meta +7 -0
  74. package/Samples~/Sound_Manager.prefab +473 -0
  75. package/Samples~/Sound_Manager.prefab.meta +7 -0
  76. package/Samples~/Sound_Manager_Events.prefab +261 -0
  77. package/Samples~/Sound_Manager_Events.prefab.meta +7 -0
  78. package/Samples~/Sound_Manager_Shell.prefab +370 -0
  79. package/Samples~/Sound_Manager_Shell.prefab.meta +7 -0
  80. package/Samples~/Sound_Player_DRE.prefab +47 -0
  81. package/Samples~/Sound_Player_DRE.prefab.meta +7 -0
  82. package/Samples~/StopAllAudio.asset +14 -0
  83. package/Samples~/StopAllAudio.asset.meta +8 -0
  84. package/Samples~/UI_Cancel_Source.prefab +130 -0
  85. package/Samples~/UI_Cancel_Source.prefab.meta +7 -0
  86. package/Samples~/UI_Select_Source.prefab +130 -0
  87. package/Samples~/UI_Select_Source.prefab.meta +7 -0
  88. package/Samples~/UI_Submit_Source.prefab +130 -0
  89. package/Samples~/UI_Submit_Source.prefab.meta +7 -0
  90. package/Samples~/Voice_SFX_Manager.prefab +146 -0
  91. package/Samples~/Voice_SFX_Manager.prefab.meta +7 -0
  92. package/Samples~/Voice_SFX_Manager_Shell.prefab +49 -0
  93. package/Samples~/Voice_SFX_Manager_Shell.prefab.meta +7 -0
  94. package/Samples~/Voice_Source.prefab +130 -0
  95. package/Samples~/Voice_Source.prefab.meta +7 -0
  96. package/SelectSFXOnSceneEvent.cs +22 -0
  97. package/SelectSFXOnSceneEvent.cs.meta +11 -0
  98. package/SoundManager.cs +191 -0
  99. package/SoundManager.cs.meta +11 -0
  100. package/SoundManagerBase.cs +73 -0
  101. package/SoundManagerBase.cs.meta +11 -0
  102. package/SoundPlayerDRE.cs +27 -0
  103. package/SoundPlayerDRE.cs.meta +11 -0
  104. package/SoundPlayerDREUnity.cs +29 -0
  105. package/SoundPlayerDREUnity.cs.meta +11 -0
  106. package/SoundService.cs +11 -0
  107. package/SoundService.cs.meta +11 -0
  108. package/StopEnvAudioToTitle.cs +17 -0
  109. package/StopEnvAudioToTitle.cs.meta +11 -0
  110. package/VOManagerBase.cs +29 -0
  111. package/VOManagerBase.cs.meta +11 -0
  112. package/VoiceSFXManager.cs +105 -0
  113. package/VoiceSFXManager.cs.meta +11 -0
  114. package/package.json +39 -4
  115. package/package.json.meta +7 -0
  116. package/README.md +0 -3
@@ -0,0 +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
+ }
436
+ }
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: 414cacea6a270a94aa629219f679f17d
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant:
@@ -0,0 +1,115 @@
1
+ //Author: Benjamin "Sweden" Jillson : Discord: sweden_gaming For Project Eden's Garden
2
+ using DREditor.EventObjects;
3
+ #if FMOD_UNITY
4
+ using FMODUnity;
5
+ #endif
6
+ using System;
7
+ using UnityEngine;
8
+
9
+ namespace DREditor.Audio
10
+ {
11
+ /// <summary>
12
+ ///
13
+ /// </summary>
14
+ /// <remarks></remarks>
15
+ public abstract class MusicManagerBase : SoundService<MusicManagerBase>
16
+ {
17
+ /// <summary>
18
+ ///
19
+ /// </summary>
20
+ [Header("")]
21
+
22
+ [Tooltip("")]
23
+ [SerializeField] protected StringWithEvent SetMusicText = null;
24
+
25
+ /// <summary>
26
+ ///
27
+ /// </summary>
28
+ [Tooltip("")]
29
+ [SerializeField] protected SceneEvent ClearMusicText = null;
30
+
31
+ /// <summary>
32
+ ///
33
+ /// </summary>
34
+ [Tooltip("")]
35
+ [SerializeField] protected SceneEvent ResetMusicText = null;
36
+
37
+ #if FMOD_UNITY
38
+ /// <summary>
39
+ ///
40
+ /// </summary>
41
+ public event Action<StudioEventEmitter> OnMusicChange;
42
+
43
+ /// <summary>
44
+ ///
45
+ /// </summary>
46
+ /// <param name="musicSource"></param>
47
+ protected virtual void InvokeMusicChange(StudioEventEmitter musicSource) => OnMusicChange?.Invoke(musicSource);
48
+
49
+ #else
50
+ /// <summary>
51
+ ///
52
+ /// </summary>
53
+ public event Action<AudioSource> OnMusicChange;
54
+
55
+ /// <summary>
56
+ ///
57
+ /// </summary>
58
+ /// <param name="musicSource"></param>
59
+ protected virtual void InvokeMusicChange(AudioSource musicSource) => OnMusicChange?.Invoke(musicSource);
60
+ #endif
61
+
62
+
63
+
64
+ /// <summary>
65
+ ///
66
+ /// </summary>
67
+ /// <typeparam name="T"></typeparam>
68
+ /// <param name="eventName"></param>
69
+ /// <param name="skip"></param>
70
+ public abstract void PlayMusic<T>(T eventName, bool skip = false);
71
+
72
+ /// <summary>
73
+ ///
74
+ /// </summary>
75
+ /// <returns></returns>
76
+ public abstract bool MusicIsPlaying();
77
+
78
+ /// <summary>
79
+ ///
80
+ /// </summary>
81
+ public abstract void StopPlayingMusic();
82
+
83
+ /// <summary>
84
+ ///
85
+ /// </summary>
86
+ public abstract void PlayLastMusic();
87
+
88
+ /// <summary>
89
+ ///
90
+ /// </summary>
91
+ protected abstract void ResetLastPlayedMusic();
92
+
93
+ /// <summary>
94
+ ///
95
+ /// </summary>
96
+ /// <param name="duration"></param>
97
+ public abstract void FadeMusic(float duration = 1);
98
+
99
+ /// <summary>
100
+ ///
101
+ /// </summary>
102
+ public abstract void StopMusic();
103
+
104
+ /// <summary>
105
+ ///
106
+ /// </summary>
107
+ public abstract void StopSound();
108
+
109
+ /// <summary>
110
+ ///
111
+ /// </summary>
112
+ /// <returns></returns>
113
+ public abstract string GetLastPlayedMusic();
114
+ }
115
+ }
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: 35cea5ed13d7d1643ab1d44e21d2c00c
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant:
package/MusicSaver.cs ADDED
@@ -0,0 +1,127 @@
1
+ //Author: Benjamin "Sweden" Jillson : Discord: sweden_gaming For Project Eden's Garden
2
+ using DREditor.EventObjects;
3
+ using DREditor.Saving;
4
+ using System.Collections.Generic;
5
+ using UnityEngine;
6
+
7
+ namespace DREditor.Audio
8
+ {
9
+ /// <summary>
10
+ ///
11
+ /// </summary>
12
+ [ClassHeader(nameof(IDRESaveable) + ", " + nameof(IDRELoadable) + ", " + nameof(ISceneEventListener) +
13
+ "\n\n")]
14
+ public class MusicSaver : MonoBehaviour, IDRESaveable, IDRELoadable, ISceneEventListener
15
+ {
16
+ /// <summary>
17
+ ///
18
+ /// </summary>
19
+ [Tooltip("")]
20
+ [SerializeField] protected SceneEvent onFadingOutOfLoading = null;
21
+
22
+ #if FMOD_UNITY
23
+ /// <summary>
24
+ ///
25
+ /// </summary>
26
+ [Tooltip("")]
27
+ [SerializeField] protected MusicManager musicManager;
28
+
29
+ /// <summary>
30
+ ///
31
+ /// </summary>
32
+ [Tooltip("")]
33
+ [SerializeField] protected string musicSaveKey = "MusicData";
34
+ #else
35
+ /// <summary>
36
+ ///
37
+ /// </summary>
38
+ [Tooltip("")]
39
+ [SerializeField] protected MusicManager musicManager;
40
+
41
+ /// <summary>
42
+ ///
43
+ /// </summary>
44
+ [Tooltip("")]
45
+ [SerializeField] protected Playlist jukeBox = null;
46
+
47
+ /// <summary>
48
+ ///
49
+ /// </summary>
50
+ [Tooltip("")]
51
+ [SerializeField] protected string musicSaveKey = "MusicData";
52
+ #endif
53
+
54
+ /// <summary>
55
+ ///
56
+ /// </summary>
57
+ protected string loadedMusic = "";
58
+
59
+ /// <summary>
60
+ ///
61
+ /// </summary>
62
+ protected bool registered = false;
63
+
64
+
65
+ /// <inheritdoc/>
66
+ public virtual void Save(Dictionary<string, object> saveDatas) => saveDatas[musicSaveKey] = SaveMusic();
67
+
68
+ /// <inheritdoc/>
69
+ public virtual void Load(Dictionary<string, object> saveDatas) => LoadMusic(saveDatas[musicSaveKey] as string);
70
+
71
+ /// <summary>
72
+ ///
73
+ /// </summary>
74
+ /// <returns></returns>
75
+ protected virtual string SaveMusic() => musicManager.GetLastPlayedMusic();
76
+
77
+ /// <summary>
78
+ ///
79
+ /// </summary>
80
+ /// <param name="name"></param>
81
+ protected virtual void LoadMusic(string name)
82
+ {
83
+ if (name is string loadName && loadName != "")
84
+ {
85
+ loadedMusic = loadName;
86
+
87
+ if (registered)
88
+ return;
89
+
90
+ onFadingOutOfLoading.RegisterListener(this);
91
+
92
+ registered = true;
93
+ }
94
+ else
95
+ musicManager.OnLoadedMusicMissing();
96
+ }
97
+
98
+ /// <summary>
99
+ ///
100
+ /// </summary>
101
+ /// <param name="loadName"></param>
102
+ protected virtual void LoadValidMusic(string loadName)
103
+ {
104
+ #if FMOD_UNITY
105
+ musicManager.PlayValidMusic(loadName);
106
+ #else
107
+ musicManager.PlayMusic(jukeBox.GetAudioClip(loadName));
108
+ #endif
109
+ }
110
+
111
+
112
+ /// <inheritdoc/>
113
+ public virtual void OnEventRaised()
114
+ {
115
+ if (!registered)
116
+ return;
117
+
118
+ onFadingOutOfLoading.UnregisterListener(this);
119
+
120
+ registered = false;
121
+
122
+ LoadValidMusic(loadedMusic);
123
+ }
124
+
125
+ protected virtual void OnDestroy() => onFadingOutOfLoading.UnregisterListener(this);
126
+ }
127
+ }