< Summary

Class:PlayContinuousSound
Assembly:Test
File(s):E:/Unity/Unity Project/VR-Basics/Assets/_Course Library/Scripts/Core/PlayContinuousSound.cs
Covered lines:25
Uncovered lines:34
Coverable lines:59
Total lines:97
Line coverage:42.3% (25 of 59)
Covered branches:0
Total branches:0
Covered methods:6
Total methods:12
Method coverage:50% (6 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%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")]
 610    public AudioClip sound = null;
 11
 12    [Tooltip("Controls if the sound plays on start")]
 613    public bool playOnStart = false;
 14
 15    [Tooltip("The volume of the sound")]
 616    public float volume = 1.0f;
 17
 618    private AudioSource audioSource = null;
 619    private MonoBehaviour currentOwner = null;
 20
 21    private void Awake()
 322    {
 323        audioSource = GetComponent<AudioSource>();
 324        audioSource.volume = volume;
 325    }
 26
 27    private void Start()
 328    {
 329        if (playOnStart)
 030            Play();
 331    }
 32
 33    public void Play()
 634    {
 635        audioSource.clip = sound;
 636        audioSource.Play();
 637    }
 38
 39    public void Pause()
 640    {
 641        audioSource.clip = null;
 642        audioSource.Pause();
 643    }
 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()
 692    {
 693        AudioSource audioSource = GetComponent<AudioSource>();
 694        audioSource.playOnAwake = false;
 695        audioSource.loop = true;
 696    }
 97}