< Summary

Class:TutorialMusicHandler
Assembly:Onboarding
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Tutorial/Scripts/TutorialMusicHandler.cs
Covered lines:24
Uncovered lines:10
Coverable lines:34
Total lines:76
Line coverage:70.5% (24 of 34)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Awake()0%110100%
OnDestroy()0%110100%
OnRendererStateChange(...)0%110100%
TutorialActive_OnChange(...)0%3.023087.5%
TryPlayingMusic()0%8.836057.14%
OnAvatarEditorMusicPlay()0%6200%
OnAvatarEditorMusicStop()0%6200%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Tutorial/Scripts/TutorialMusicHandler.cs

#LineLine coverage
 1using System.Collections;
 2using System.Collections.Generic;
 3using UnityEngine;
 4
 5public class TutorialMusicHandler : MonoBehaviour
 6{
 7    [SerializeField] AudioEvent tutorialMusic, avatarEditorMusic;
 8
 9    bool rendererIsReady = false, tutorialHasBeenEnabled = false;
 10
 11    Coroutine fadeOut;
 12
 13    private void Awake()
 14    {
 3915        CommonScriptableObjects.tutorialActive.OnChange += TutorialActive_OnChange;
 3916        CommonScriptableObjects.rendererState.OnChange += OnRendererStateChange;
 3917        avatarEditorMusic.OnPlay += OnAvatarEditorMusicPlay;
 3918        avatarEditorMusic.OnStop += OnAvatarEditorMusicStop;
 3919    }
 20
 21    private void OnDestroy()
 22    {
 3923        CommonScriptableObjects.tutorialActive.OnChange -= TutorialActive_OnChange;
 3924        CommonScriptableObjects.rendererState.OnChange -= OnRendererStateChange;
 3925        avatarEditorMusic.OnPlay -= OnAvatarEditorMusicPlay;
 3926        avatarEditorMusic.OnStop -= OnAvatarEditorMusicStop;
 3927    }
 28
 29    void OnRendererStateChange(bool current, bool previous)
 30    {
 131        rendererIsReady = current;
 132        TryPlayingMusic();
 133    }
 34
 35    private void TutorialActive_OnChange(bool current, bool previous)
 36    {
 2437        if (current)
 38        {
 1239            tutorialHasBeenEnabled = true;
 1240            TryPlayingMusic();
 1241        }
 42        else
 43        {
 1244            if (tutorialMusic.source.isPlaying)
 045                fadeOut = CoroutineStarter.Start(tutorialMusic.FadeOut(3f));
 1246            tutorialHasBeenEnabled = false;
 47        }
 1248    }
 49
 50    void TryPlayingMusic()
 51    {
 1352        if (DCL.Tutorial.TutorialController.i.userAlreadyDidTheTutorial)
 353            return;
 54
 1055        if (rendererIsReady && tutorialHasBeenEnabled && !tutorialMusic.source.isPlaying)
 56        {
 057            if (fadeOut != null)
 58            {
 059                CoroutineStarter.Stop(fadeOut);
 60            }
 061            tutorialMusic.Play();
 62        }
 1063    }
 64
 65    void OnAvatarEditorMusicPlay()
 66    {
 067        if (tutorialMusic.source.isPlaying)
 068            fadeOut = CoroutineStarter.Start(tutorialMusic.FadeOut(1.5f, false));
 069    }
 70
 71    void OnAvatarEditorMusicStop()
 72    {
 073        if (tutorialMusic.source.isPlaying)
 074            CoroutineStarter.Start(tutorialMusic.FadeIn(2.5f));
 075    }
 76}