< Summary

Class:Door
Assembly:Test
File(s):D:/--UnityProject/VR/subjects/unity-vr-maze-master/unity-vr-maze-master/Assets/Maze/Scripts/Door.cs
Covered lines:50
Uncovered lines:5
Coverable lines:55
Total lines:133
Line coverage:90.9% (50 of 55)
Covered branches:0
Total branches:0
Covered methods:7
Total methods:7
Method coverage:100% (7 of 7)

Coverage History

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Door()0%000100%
Awake()0%000100%
Update()0%00085.71%
Open()0%00070%
Close()0%000100%
Unlock()0%000100%
PlaySound(...)0%000100%

File(s)

D:/--UnityProject/VR/subjects/unity-vr-maze-master/unity-vr-maze-master/Assets/Maze/Scripts/Door.cs

#LineLine coverage
 1using System.Collections;
 2using System.Collections.Generic;
 3using System.Diagnostics.CodeAnalysis;
 4using UnityEngine;
 5using VRExplorer;
 6public class Door : MonoBehaviour, ITriggerableEntity
 7{
 8    #region Entity
 9    [ExcludeFromCodeCoverage] public float TriggeringTime => 2f;
 10    [ExcludeFromCodeCoverage] public string Name => Str.Button;
 11    [ExcludeFromCodeCoverage]
 12    public void Triggerring()
 13    {
 14        Open();
 15    }
 16
 17    [ExcludeFromCodeCoverage]
 18    public void Triggerred()
 19    {
 20        Close();
 21    }
 22    #endregion
 23
 24    private enum State
 25    {
 26        Closed,
 27        Opening,
 28        Closing,
 29        Opened
 30    }
 31
 32    [Header("Sounds")]
 1933    public AudioClip open_fail_sound = null;
 1934    public AudioClip open_success_sound = null;
 35
 1936    private bool locked = true;
 1937    private State _state = State.Closed;
 1938    private float _slide_speed = 2.0f;
 1939    private float _opened_position_offset = 7.0f;
 40    private Vector3 _initial_position;
 1941    private Vector3 _slide_vector = new Vector3(0f, 1f, 0f);
 42
 43
 1944    void Awake() {
 45        // save initial door position
 1946        _initial_position = gameObject.transform.position;
 1947    }
 48
 10477149    void Update() {
 10477150        switch (_state)
 51        {
 52            case State.Closed:
 9827353                break;
 54
 55            case State.Opening:
 146056                if (gameObject.transform.position.y < _initial_position.y + _opened_position_offset)
 146057                {
 58                    // slide the door to open
 146059                    gameObject.transform.position = gameObject.transform.position + _slide_vector * _slide_speed * Time.
 146060                } else
 061                {
 062                    _state = State.Opened;
 063                }
 146064                break;
 65
 66            case State.Closing:
 92767                if (gameObject.transform.position.y > _initial_position.y)
 92368                {
 69                    // slide the door to open
 92370                    gameObject.transform.position = gameObject.transform.position - _slide_vector * _slide_speed * Time.
 92371                }
 72                else
 473                {
 474                    _state = State.Opened;
 475                }
 92776                break;
 77
 78            case State.Opened:
 411179                break;
 80        }
 10477181    }
 82
 83    /**
 84     * Method that opens the door
 85     */
 86    public void Open()
 587    {
 88        // only affects closed door
 589        if (_state == State.Closed && !locked)
 590        {
 91            // start opening
 592            PlaySound(open_success_sound);
 593            _state = State.Opening;
 594        } else {
 95            // cannot open
 096            PlaySound(open_fail_sound);
 097        }
 598    }
 99
 100    /**
 101     * Method that closes the door
 102     */
 103    public void Close()
 5104    {
 105        // only affects opened or opening door
 5106        if (_state == State.Opened || _state == State.Opening)
 5107        {
 108            // start closing
 5109            PlaySound(open_success_sound);
 5110            _state = State.Closing;
 5111        }
 5112    }
 113
 114    /**
 115     * Unlock the door
 116     */
 117    public void Unlock()
 15118    {
 15119        locked = false;
 15120    }
 121
 122    /**
 123     * Utility method for convenience
 124     */
 125    protected void PlaySound(AudioClip clip)
 10126    {
 10127        AudioSource player = gameObject.GetComponent<AudioSource>();
 10128        player.clip = clip;
 10129        player.Play();
 10130    }
 131
 132
 133}