< Summary

Class:PlaySoundsFromList
Assembly:Test
File(s):E:/Unity/Unity Project/VR-Room/Assets/_Course Library/Scripts/Test/PlaySoundsFromList.cs
Covered lines:52
Uncovered lines:4
Coverable lines:56
Total lines:92
Line coverage:92.8% (52 of 56)
Covered branches:0
Total branches:0
Covered methods:11
Total methods:12
Method coverage:91.6% (11 of 12)

Coverage History

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
PlaySoundsFromList()0%000100%
Awake()0%000100%
PlayPause()0%000100%
NextClip()0%000100%
PreviousClip()0%000100%
RandomClip()0%000100%
PlayAtIndex(...)0%0000%
PauseClip()0%000100%
StopClip()0%000100%
PlayCurrentClip()0%000100%
PlayClip()0%000100%
OnValidate()0%000100%

File(s)

E:/Unity/Unity Project/VR-Room/Assets/_Course Library/Scripts/Test/PlaySoundsFromList.cs

#LineLine coverage
 1using System.Collections.Generic;
 2using UnityEngine;
 3
 4/// <summary>
 5/// Play from a list of sounds using next, previous, and random
 6/// </summary>
 7[RequireComponent(typeof(AudioSource))]
 8public class PlaySoundsFromList : MonoBehaviour
 9{
 10    [Tooltip("Loop the currently playing sound")]
 211    public bool shouldLoop = false;
 212    private bool playing = false;
 13
 14    [Tooltip("The list of audio clips to play from")]
 215    public List<AudioClip> audioClips = new List<AudioClip>();
 16
 217    private AudioSource audioSource = null;
 218    private int index = 0;
 19
 20    private void Awake()
 121    {
 122        audioSource = GetComponent<AudioSource>();
 123    }
 24
 25    public void PlayPause()
 326    {
 327        if(playing)
 228        {
 229            playing = false;
 230            PauseClip();
 231        }
 32        else
 133        {
 134            playing = true;
 135            PlayClip();
 136        }
 337    }
 38    public void NextClip()
 339    {
 340        index = ++index % audioClips.Count;
 341        PlayClip();
 342    }
 43
 44    public void PreviousClip()
 145    {
 146        index = --index % audioClips.Count;
 147        PlayClip();
 148    }
 49
 50    public void RandomClip()
 151    {
 152        index = Random.Range(0, audioClips.Count);
 153        PlayClip();
 154    }
 55
 56    public void PlayAtIndex(int value)
 057    {
 058        index = Mathf.Clamp(value, 0, audioClips.Count);
 059        PlayClip();
 060    }
 61
 62    public void PauseClip()
 363    {
 364        playing = false;
 365        audioSource.Pause();
 366    }
 67
 68    public void StopClip()
 169    {
 170        playing = false;
 171        audioSource.Stop();
 172    }
 73
 74    public void PlayCurrentClip()
 175    {
 176        playing = true;
 177        PlayClip();
 178    }
 79
 80    private void PlayClip()
 781    {
 782        playing = true;
 783        audioSource.clip = audioClips[Mathf.Abs(index)];
 784        audioSource.Play();
 785    }
 86
 87    private void OnValidate()
 288    {
 289        AudioSource audioSource = GetComponent<AudioSource>();
 290        audioSource.loop = shouldLoop;
 291    }
 92}