| | 1 | | using System.Collections; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using DCL; |
| | 4 | | using UnityEngine; |
| | 5 | |
|
| | 6 | | public class TutorialMusicHandler : MonoBehaviour |
| | 7 | | { |
| | 8 | | [SerializeField] AudioEvent tutorialMusic, avatarEditorMusic; |
| | 9 | |
|
| | 10 | | Coroutine fadeOut; |
| | 11 | |
|
| | 12 | | private void Awake() |
| | 13 | | { |
| 41 | 14 | | avatarEditorMusic.OnPlay += OnAvatarEditorMusicPlay; |
| 41 | 15 | | avatarEditorMusic.OnStop += OnAvatarEditorMusicStop; |
| 41 | 16 | | } |
| | 17 | |
|
| | 18 | | private void OnDestroy() |
| | 19 | | { |
| 41 | 20 | | avatarEditorMusic.OnPlay -= OnAvatarEditorMusicPlay; |
| 41 | 21 | | avatarEditorMusic.OnStop -= OnAvatarEditorMusicStop; |
| | 22 | |
|
| 41 | 23 | | if (fadeOut != null) |
| | 24 | | { |
| 18 | 25 | | CoroutineStarter.Stop(fadeOut); |
| 18 | 26 | | fadeOut = null; |
| | 27 | | } |
| 41 | 28 | | } |
| | 29 | | public void StopTutorialMusic() |
| | 30 | | { |
| 68 | 31 | | DataStore.i.virtualAudioMixer.sceneSFXVolume.Set(1f); |
| | 32 | |
|
| 68 | 33 | | if (fadeOut != null) |
| | 34 | | { |
| 17 | 35 | | CoroutineStarter.Stop(fadeOut); |
| 17 | 36 | | fadeOut = null; |
| | 37 | | } |
| | 38 | |
|
| 68 | 39 | | if (tutorialMusic.source.isPlaying) |
| 35 | 40 | | fadeOut = CoroutineStarter.Start(tutorialMusic.FadeOut(3f)); |
| 68 | 41 | | } |
| | 42 | |
|
| | 43 | | public void TryPlayingMusic() |
| | 44 | | { |
| 20 | 45 | | if (DCL.Tutorial.TutorialController.i.userAlreadyDidTheTutorial) |
| 2 | 46 | | return; |
| | 47 | |
|
| 18 | 48 | | if (!tutorialMusic.source.isPlaying) |
| | 49 | | { |
| 18 | 50 | | if (fadeOut != null) |
| | 51 | | { |
| 0 | 52 | | CoroutineStarter.Stop(fadeOut); |
| | 53 | | } |
| 18 | 54 | | DataStore.i.virtualAudioMixer.sceneSFXVolume.Set(0f); |
| 18 | 55 | | tutorialMusic.Play(); |
| | 56 | | } |
| 18 | 57 | | } |
| | 58 | |
|
| | 59 | | void OnAvatarEditorMusicPlay() |
| | 60 | | { |
| 0 | 61 | | if (tutorialMusic.source.isPlaying) |
| 0 | 62 | | fadeOut = CoroutineStarter.Start(tutorialMusic.FadeOut(1.5f, false)); |
| 0 | 63 | | } |
| | 64 | |
|
| | 65 | | void OnAvatarEditorMusicStop() |
| | 66 | | { |
| 0 | 67 | | if (tutorialMusic.source.isPlaying) |
| 0 | 68 | | CoroutineStarter.Start(tutorialMusic.FadeIn(2.5f)); |
| 0 | 69 | | } |
| | 70 | | } |