< Summary

Class:ButtonVR
Assembly:Test
File(s):E:/Unity/Unity Project/VR-Adventure/Assets/Scripts/ButtonVR.cs
Covered lines:9
Uncovered lines:17
Coverable lines:26
Total lines:64
Line coverage:34.6% (9 of 26)
Covered branches:0
Total branches:0
Covered methods:2
Total methods:4
Method coverage:50% (2 of 4)

Coverage History

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Start()0%000100%
OnTriggerEnter(...)0%0000%
OnTriggerExit(...)0%0000%
SpawnSphere()0%000100%

File(s)

E:/Unity/Unity Project/VR-Adventure/Assets/Scripts/ButtonVR.cs

#LineLine coverage
 1using BNG;
 2using System.Collections;
 3using System.Collections.Generic;
 4using System.Diagnostics.CodeAnalysis;
 5using UnityEngine;
 6using UnityEngine.Events;
 7using HenryLab;
 8public class ButtonVR : MonoBehaviour, ITriggerableEntity
 9{
 10    [ExcludeFromCodeCoverage] public float TriggeringTime => 1.5f;
 11    [ExcludeFromCodeCoverage] public string Name => Str.Triggerable;
 12
 13    [ExcludeFromCodeCoverage]
 14    public void Triggerring()
 15    {
 16        onPress?.Invoke();
 17    }
 18
 19    [ExcludeFromCodeCoverage]
 20    public void Triggerred()
 21    {
 22        onRelease?.Invoke();
 23    }
 24
 25    public GameObject button;
 26    public UnityEvent onPress;
 27    public UnityEvent onRelease;
 28    GameObject presser;
 29    bool isPressed;
 30
 31    void Start()
 232    {
 233        isPressed = false;
 234    }
 35
 36    private void OnTriggerEnter(Collider other)
 037    {
 038        if(!isPressed)
 039        {
 040            button.transform.localPosition = new Vector3(-0.52f, 0.279f, -0.133f);
 041            presser = other.gameObject;
 042            onPress.Invoke();
 043            isPressed = true;
 044        }
 045    }
 46
 47    private void OnTriggerExit(Collider other)
 048    {
 049        if(other.gameObject == presser)
 050        {
 051            button.transform.localPosition = new Vector3(-0.544f, 0.279f, -0.133f);
 052            onRelease.Invoke();
 053            isPressed = false;
 054        }
 055    }
 56
 57    public void SpawnSphere()
 358    {
 359        GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
 360        sphere.transform.localScale = new Vector3(0.2f, 0.2f, 0.2f);
 361        sphere.transform.localPosition = new Vector3(-0.98f, -0.18f, 0.4f);
 362        sphere.AddComponent<Rigidbody>();
 363    }
 64}