< Summary

Class:PlayContinuousSound
Assembly:Test
File(s):D:/--UnityProject/VR/VRExplorer_subjects/VR-Room/Assets/_Course Library/Scripts/Test/PlayContinuousSound.cs
Covered lines:39
Uncovered lines:20
Coverable lines:59
Total lines:97
Line coverage:66.1% (39 of 59)
Covered branches:0
Total branches:0
Covered methods:8
Total methods:12
Method coverage:66.6% (8 of 12)

Coverage History

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
PlayContinuousSound()0%000100%
Awake()0%000100%
Start()0%00075%
Play()0%000100%
Pause()0%000100%
PlayWithExclusivity(...)0%000100%
StopWithExclusivity(...)0%000100%
TogglePlay()0%0000%
SetPlay(...)0%0000%
IsPlaying()0%0000%
SetClip(...)0%0000%
OnValidate()0%000100%

File(s)

D:/--UnityProject/VR/VRExplorer_subjects/VR-Room/Assets/_Course Library/Scripts/Test/PlayContinuousSound.cs

#LineLine coverage
 1using UnityEngine;
 2
 3/// <summary>
 4/// Play a long continuous sound
 5/// </summary>
 6[RequireComponent(typeof(AudioSource))]
 7public class PlayContinuousSound : MonoBehaviour
 8{
 9    [Tooltip("The sound that is played")]
 1010    public AudioClip sound = null;
 11
 12    [Tooltip("Controls if the sound plays on start")]
 1013    public bool playOnStart = false;
 14
 15    [Tooltip("The volume of the sound")]
 1016    public float volume = 1.0f;
 17
 1018    private AudioSource audioSource = null;
 1019    private MonoBehaviour currentOwner = null;
 20
 21    private void Awake()
 822    {
 823        audioSource = GetComponent<AudioSource>();
 824        audioSource.volume = volume;
 825    }
 26
 27    private void Start()
 828    {
 829        if (playOnStart)
 030            Play();
 831    }
 32
 33    public void Play()
 1234    {
 1235        audioSource.clip = sound;
 1236        audioSource.Play();
 1237    }
 38
 39    public void Pause()
 1240    {
 1241        audioSource.clip = null;
 1242        audioSource.Pause();
 1243    }
 44
 45    public void PlayWithExclusivity(MonoBehaviour owner)
 346    {
 347        if (currentOwner == null)
 348        {
 349            currentOwner = owner;
 350            Play();
 351        }
 352    }
 53
 54    public void StopWithExclusivity(MonoBehaviour owner)
 355    {
 356        if (currentOwner == owner)
 357        {
 358            currentOwner = null;
 359            Pause();
 360        }
 361    }
 62
 63    public void TogglePlay()
 064    {
 065        bool isPlaying = !IsPlaying();
 066        SetPlay(isPlaying);
 067    }
 68
 69    public void SetPlay(bool playAudio)
 070    {
 071        if (playAudio)
 072        {
 073            Play();
 074        }
 75        else
 076        {
 077            Pause();
 078        }
 079    }
 80
 81    public bool IsPlaying()
 082    {
 083        return audioSource.isPlaying;
 084    }
 85
 86    public void SetClip(AudioClip audioClip)
 087    {
 088        sound = audioClip;
 089    }
 90
 91    private void OnValidate()
 1092    {
 1093        AudioSource audioSource = GetComponent<AudioSource>();
 1094        audioSource.playOnAwake = false;
 1095        audioSource.loop = true;
 1096    }
 97}