< Summary

Class:PlayContinuousSound
Assembly:Test
File(s):E:/Unity/Unity Project/VR-Basics/Assets/_Course Library/Scripts/Core/PlayContinuousSound.cs
Covered lines:17
Uncovered lines:42
Coverable lines:59
Total lines:97
Line coverage:28.8% (17 of 59)
Covered branches:0
Total branches:0
Covered methods:4
Total methods:12
Method coverage:33.3% (4 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%0000%
Pause()0%0000%
PlayWithExclusivity(...)0%0000%
StopWithExclusivity(...)0%0000%
TogglePlay()0%0000%
SetPlay(...)0%0000%
IsPlaying()0%0000%
SetClip(...)0%0000%
OnValidate()0%000100%

File(s)

E:/Unity/Unity Project/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()
 034    {
 035        audioSource.clip = sound;
 036        audioSource.Play();
 037    }
 38
 39    public void Pause()
 040    {
 041        audioSource.clip = null;
 042        audioSource.Pause();
 043    }
 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()
 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()
 1592    {
 1593        AudioSource audioSource = GetComponent<AudioSource>();
 1594        audioSource.playOnAwake = false;
 1595        audioSource.loop = true;
 1596    }
 97}