< Summary

Class:MusicManager
Assembly:Test
File(s):E:/Unity/Unity Project/VR-Cooking-Demo/Assets/_Scripts/MusicManager.cs
Covered lines:14
Uncovered lines:5
Coverable lines:19
Total lines:63
Line coverage:73.6% (14 of 19)
Covered branches:0
Total branches:0
Covered methods:2
Total methods:2
Method coverage:100% (2 of 2)

Coverage History

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Start()0%000100%
PlayMusic()0%00061.54%

File(s)

E:/Unity/Unity Project/VR-Cooking-Demo/Assets/_Scripts/MusicManager.cs

#LineLine coverage
 1/*
 2 *
 3 * Code by:
 4 *      Dimitrios Vlachos
 5 *      djv1@student.london.ac.uk
 6 *      dimitri.j.vlachos@gmail.com
 7 *
 8 */
 9
 10using System.Collections;
 11using System.Collections.Generic;
 12using UnityEngine;
 13
 14public class MusicManager : MonoBehaviour
 15{
 16    [Header("Music")]
 17    [SerializeField, Tooltip("List of music to cycle through")]
 18    List<AudioClip> inGameMusic;
 19    [SerializeField] AudioSource audioSource;
 20
 21    private int songRotation;
 22    void Start()
 123    {
 124        audioSource = GetComponent<AudioSource>();
 25
 26        // Select random starting song
 127        int randomSong = Random.Range(0,inGameMusic.Count);
 128        songRotation = randomSong;
 29
 130        StartCoroutine(PlayMusic());
 131    }
 32
 33    IEnumerator PlayMusic()
 134    {
 35        // Get the next clip to play
 136        AudioClip clip = inGameMusic[songRotation];
 37
 38        // Play selected song
 39        //Debug.Log("Now playing... " + clip.name);
 140        audioSource.clip = clip;
 141        audioSource.Play();
 42
 43        // Increment to select the next song
 144        songRotation++;
 45
 46        // If we've incremented too far, loop back around
 147        if (songRotation >= inGameMusic.Count)
 048        {
 049            songRotation = 0;
 050        }
 51
 52        // Get the length of the selected song
 153        float songLength = clip.length;
 54        //Debug.Log("Waiting " + songLength + " until next song...");
 55
 56        // Wait that long before playing the next one
 157        yield return new WaitForSeconds(songLength + 1);
 58
 59        // Play the next song!
 60        //Debug.Log("Looping back!");
 061        StartCoroutine(PlayMusic());
 062    }
 63}

Methods/Properties

Start()
PlayMusic()