< Summary

Class:TutorialMusicHandler
Assembly:Onboarding
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Tutorial/Scripts/TutorialMusicHandler.cs
Covered lines:21
Uncovered lines:13
Coverable lines:34
Total lines:77
Line coverage:61.7% (21 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%2100%
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] DCL.Tutorial.TutorialController tutorialController;
 8    [SerializeField] AudioEvent tutorialMusic, avatarEditorMusic;
 9
 10    bool rendererIsReady = false, tutorialHasBeenEnabled = false;
 11
 12    Coroutine fadeOut;
 13
 14    private void Awake()
 15    {
 1016        CommonScriptableObjects.tutorialActive.OnChange += TutorialActive_OnChange;
 1017        CommonScriptableObjects.rendererState.OnChange += OnRendererStateChange;
 1018        avatarEditorMusic.OnPlay += OnAvatarEditorMusicPlay;
 1019        avatarEditorMusic.OnStop += OnAvatarEditorMusicStop;
 1020    }
 21
 22    private void OnDestroy()
 23    {
 1024        CommonScriptableObjects.tutorialActive.OnChange -= TutorialActive_OnChange;
 1025        CommonScriptableObjects.rendererState.OnChange -= OnRendererStateChange;
 1026        avatarEditorMusic.OnPlay -= OnAvatarEditorMusicPlay;
 1027        avatarEditorMusic.OnStop -= OnAvatarEditorMusicStop;
 1028    }
 29
 30    void OnRendererStateChange(bool current, bool previous)
 31    {
 032        rendererIsReady = current;
 033        TryPlayingMusic();
 034    }
 35
 36    private void TutorialActive_OnChange(bool current, bool previous)
 37    {
 5238        if (current)
 39        {
 2640            tutorialHasBeenEnabled = true;
 2641            TryPlayingMusic();
 2642        }
 43        else
 44        {
 2645            if (tutorialMusic.source.isPlaying)
 046                fadeOut = CoroutineStarter.Start(tutorialMusic.FadeOut(3f));
 2647            tutorialHasBeenEnabled = false;
 48        }
 2649    }
 50
 51    void TryPlayingMusic()
 52    {
 2653        if (tutorialController.userAlreadyDidTheTutorial)
 654            return;
 55
 2056        if (rendererIsReady && tutorialHasBeenEnabled && !tutorialMusic.source.isPlaying)
 57        {
 058            if (fadeOut != null)
 59            {
 060                CoroutineStarter.Stop(fadeOut);
 61            }
 062            tutorialMusic.Play();
 63        }
 2064    }
 65
 66    void OnAvatarEditorMusicPlay()
 67    {
 068        if (tutorialMusic.source.isPlaying)
 069            fadeOut = CoroutineStarter.Start(tutorialMusic.FadeOut(1.5f, false));
 070    }
 71
 72    void OnAvatarEditorMusicStop()
 73    {
 074        if (tutorialMusic.source.isPlaying)
 075            CoroutineStarter.Start(tutorialMusic.FadeIn(2.5f));
 076    }
 77}