< Summary

Class:PlayContinuousSound
Assembly:Test
File(s):D:/--UnityProject/VR/_____ISSTA 26/VR-Basics/Assets/_Course Library/Scripts/Core/PlayContinuousSound.cs
Covered lines:41
Uncovered lines:18
Coverable lines:59
Total lines:97
Line coverage:69.4% (41 of 59)
Covered branches:0
Total branches:0
Covered methods:9
Total methods:12
Method coverage:75% (9 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%0000%
StopWithExclusivity(...)0%0000%
TogglePlay()0%000100%
SetPlay(...)0%000100%
IsPlaying()0%000100%
SetClip(...)0%0000%
OnValidate()0%000100%

File(s)

D:/--UnityProject/VR/_____ISSTA 26/VR-Basics/Assets/_Course Library/Scripts/Core/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")]
 1810    public AudioClip sound = null;
 11
 12    [Tooltip("Controls if the sound plays on start")]
 1813    public bool playOnStart = false;
 14
 15    [Tooltip("The volume of the sound")]
 1816    public float volume = 1.0f;
 17
 1818    private AudioSource audioSource = null;
 1819    private MonoBehaviour currentOwner = null;
 20
 21    private void Awake()
 922    {
 923        audioSource = GetComponent<AudioSource>();
 924        audioSource.volume = volume;
 925    }
 26
 27    private void Start()
 928    {
 929        if (playOnStart)
 030            Play();
 931    }
 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)
 046    {
 047        if (currentOwner == null)
 048        {
 049            currentOwner = owner;
 050            Play();
 051        }
 052    }
 53
 54    public void StopWithExclusivity(MonoBehaviour owner)
 055    {
 056        if (currentOwner == owner)
 057        {
 058            currentOwner = null;
 059            Pause();
 060        }
 061    }
 62
 63    public void TogglePlay()
 664    {
 665        bool isPlaying = !IsPlaying();
 666        SetPlay(isPlaying);
 667    }
 68
 69    public void SetPlay(bool playAudio)
 670    {
 671        if (playAudio)
 372        {
 373            Play();
 374        }
 75        else
 376        {
 377            Pause();
 378        }
 679    }
 80
 81    public bool IsPlaying()
 1482    {
 1483        return audioSource.isPlaying;
 1484    }
 85
 86    public void SetClip(AudioClip audioClip)
 087    {
 088        sound = audioClip;
 089    }
 90
 91    private void OnValidate()
 1892    {
 1893        AudioSource audioSource = GetComponent<AudioSource>();
 1894        audioSource.playOnAwake = false;
 1895        audioSource.loop = true;
 1896    }
 97}