< Summary

Class:PlaySoundsFromList
Assembly:Test
File(s):D:/--UnityProject/VR/_____ISSTA 26/VR-Room/Assets/_Course Library/Scripts/Test/PlaySoundsFromList.cs
Covered lines:48
Uncovered lines:8
Coverable lines:56
Total lines:92
Line coverage:85.7% (48 of 56)
Covered branches:0
Total branches:0
Covered methods:10
Total methods:12
Method coverage:83.3% (10 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%0000%
RandomClip()0%000100%
PlayAtIndex(...)0%0000%
PauseClip()0%000100%
StopClip()0%000100%
PlayCurrentClip()0%000100%
PlayClip()0%000100%
OnValidate()0%000100%

File(s)

D:/--UnityProject/VR/_____ISSTA 26/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")]
 411    public bool shouldLoop = false;
 412    private bool playing = false;
 13
 14    [Tooltip("The list of audio clips to play from")]
 415    public List<AudioClip> audioClips = new List<AudioClip>();
 16
 417    private AudioSource audioSource = null;
 418    private int index = 0;
 19
 20    private void Awake()
 121    {
 122        audioSource = GetComponent<AudioSource>();
 123    }
 24
 25    public void PlayPause()
 226    {
 227        if(playing)
 128        {
 129            playing = false;
 130            PauseClip();
 131        }
 32        else
 133        {
 134            playing = true;
 135            PlayClip();
 136        }
 237    }
 38    public void NextClip()
 339    {
 340        index = ++index % audioClips.Count;
 341        PlayClip();
 342    }
 43
 44    public void PreviousClip()
 045    {
 046        index = --index % audioClips.Count;
 047        PlayClip();
 048    }
 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()
 263    {
 264        playing = false;
 265        audioSource.Pause();
 266    }
 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()
 681    {
 682        playing = true;
 683        audioSource.clip = audioClips[Mathf.Abs(index)];
 684        audioSource.Play();
 685    }
 86
 87    private void OnValidate()
 488    {
 489        AudioSource audioSource = GetComponent<AudioSource>();
 490        audioSource.loop = shouldLoop;
 491    }
 92}