< Summary

Class:PlaySoundsFromList
Assembly:Test
File(s):D:/--UnityProject/VR/VRExplorer_subjects/VR-Room/Assets/_Course Library/Scripts/Test/PlaySoundsFromList.cs
Covered lines:32
Uncovered lines:24
Coverable lines:56
Total lines:92
Line coverage:57.1% (32 of 56)
Covered branches:0
Total branches:0
Covered methods:7
Total methods:12
Method coverage:58.3% (7 of 12)

Coverage History

Metrics

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

File(s)

D:/--UnityProject/VR/VRExplorer_subjects/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")]
 511    public bool shouldLoop = false;
 512    private bool playing = false;
 13
 14    [Tooltip("The list of audio clips to play from")]
 515    public List<AudioClip> audioClips = new List<AudioClip>();
 16
 517    private AudioSource audioSource = null;
 518    private int index = 0;
 19
 20    private void Awake()
 421    {
 422        audioSource = GetComponent<AudioSource>();
 423    }
 24
 25    public void PlayPause()
 226    {
 227        if(playing)
 228        {
 229            playing = false;
 230            PauseClip();
 231        }
 32        else
 033        {
 034            playing = true;
 035            PlayClip();
 036        }
 237    }
 38    public void NextClip()
 239    {
 240        index = ++index % audioClips.Count;
 241        PlayClip();
 242    }
 43
 44    public void PreviousClip()
 045    {
 046        index = --index % audioClips.Count;
 047        PlayClip();
 048    }
 49
 50    public void RandomClip()
 051    {
 052        index = Random.Range(0, audioClips.Count);
 053        PlayClip();
 054    }
 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()
 069    {
 070        playing = false;
 071        audioSource.Stop();
 072    }
 73
 74    public void PlayCurrentClip()
 075    {
 076        playing = true;
 077        PlayClip();
 078    }
 79
 80    private void PlayClip()
 281    {
 282        playing = true;
 283        audioSource.clip = audioClips[Mathf.Abs(index)];
 284        audioSource.Play();
 285    }
 86
 87    private void OnValidate()
 588    {
 589        AudioSource audioSource = GetComponent<AudioSource>();
 590        audioSource.loop = shouldLoop;
 591    }
 92}