< 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")]
 1510    public AudioClip sound = null;
 11
 12    [Tooltip("Controls if the sound plays on start")]
 1513    public bool playOnStart = false;
 14
 15    [Tooltip("The volume of the sound")]
 1516    public float volume = 1.0f;
 17
 1518    private AudioSource audioSource = null;
 1519    private MonoBehaviour currentOwner = null;
 20
 21    private void Awake()
 622    {
 623        audioSource = GetComponent<AudioSource>();
 624        audioSource.volume = volume;
 625    }
 26
 27    private void Start()
 628    {
 629        if (playOnStart)
 030            Play();
 631    }
 32
 33    public void Play()
 1134    {
 1135        audioSource.clip = sound;
 1136        audioSource.Play();
 1137    }
 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()
 564    {
 565        bool isPlaying = !IsPlaying();
 566        SetPlay(isPlaying);
 567    }
 68
 69    public void SetPlay(bool playAudio)
 570    {
 571        if (playAudio)
 272        {
 273            Play();
 274        }
 75        else
 376        {
 377            Pause();
 378        }
 579    }
 80
 81    public bool IsPlaying()
 882    {
 883        return audioSource.isPlaying;
 884    }
 85
 86    public void SetClip(AudioClip audioClip)
 087    {
 088        sound = audioClip;
 089    }
 90
 91    private void OnValidate()
 1592    {
 1593        AudioSource audioSource = GetComponent<AudioSource>();
 1594        audioSource.playOnAwake = false;
 1595        audioSource.loop = true;
 1596    }
 97}