< Summary

Class:PlayContinuousSound
Assembly:Test
File(s):E:/Unity/Unity Project/VR-Room/Assets/_Course Library/Scripts/Test/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-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")]
 810    public AudioClip sound = null;
 11
 12    [Tooltip("Controls if the sound plays on start")]
 813    public bool playOnStart = false;
 14
 15    [Tooltip("The volume of the sound")]
 816    public float volume = 1.0f;
 17
 818    private AudioSource audioSource = null;
 819    private MonoBehaviour currentOwner = null;
 20
 21    private void Awake()
 422    {
 423        audioSource = GetComponent<AudioSource>();
 424        audioSource.volume = volume;
 425    }
 26
 27    private void Start()
 428    {
 429        if (playOnStart)
 030            Play();
 431    }
 32
 33    public void Play()
 434    {
 435        audioSource.clip = sound;
 436        audioSource.Play();
 437    }
 38
 39    public void Pause()
 240    {
 241        audioSource.clip = null;
 242        audioSource.Pause();
 243    }
 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()
 892    {
 893        AudioSource audioSource = GetComponent<AudioSource>();
 894        audioSource.playOnAwake = false;
 895        audioSource.loop = true;
 896    }
 97}