< Summary

Class:OnTilt
Assembly:Test
File(s):E:/Unity/Unity Project/VR-Room/Assets/_Course Library/Scripts/Test/OnTilt.cs
Covered lines:13
Uncovered lines:12
Coverable lines:25
Total lines:76
Line coverage:52% (13 of 25)
Covered branches:0
Total branches:0
Covered methods:3
Total methods:4
Method coverage:75% (3 of 4)

Coverage History

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
OnTilt()0%000100%
Update()0%000100%
CheckOrientation()0%00037.5%
OnReleased()0%0000%

File(s)

E:/Unity/Unity Project/VR-Room/Assets/_Course Library/Scripts/Test/OnTilt.cs

#LineLine coverage
 1using BNG;
 2using System;
 3using UnityEngine;
 4using System.Diagnostics.CodeAnalysis;
 5using UnityEngine.Events;
 6using HenryLab;
 7
 8/// <summary>
 9/// When an object is tilted, run some functionality
 10/// Used with a grabable object
 11/// </summary>
 12public class OnTilt : MonoBehaviour, IGrabbableEntity
 13{
 14    [ExcludeFromCodeCoverage]
 15    public Grabbable Grabbable
 16    {
 17        get
 18        {
 19            var g = GetComponent<Grabbable>();
 20            if(g) return g;
 21            return gameObject.AddComponent<Grabbable>();
 22        }
 23    }
 24    [ExcludeFromCodeCoverage] public string Name => Str.Grabbable;
 25    [ExcludeFromCodeCoverage] public Transform Destination => null;
 26
 27    [ExcludeFromCodeCoverage]
 28    public void OnGrabbed()
 29    {
 30    }
 31
 32    [Tooltip("Tilt range, 0 - 180 degrees")]
 233    [Range(0, 1)] public float threshold = 0.1f;
 34
 35    [Serializable] public class TiltEvent : UnityEvent<MonoBehaviour> { }
 36
 37    // Threshold has been broken
 238    public TiltEvent OnBegin = new TiltEvent();
 39
 40    // Threshold is no longer broken
 241    public TiltEvent OnEnd = new TiltEvent();
 42
 243    private bool withinThreshold = false;
 44
 45    private void Update()
 86546    {
 86547        CheckOrientation();
 86548    }
 49
 50    private void CheckOrientation()
 86551    {
 86552        float similarity = Vector3.Dot(-transform.up, Vector3.up);
 86553        similarity = Mathf.InverseLerp(0, 1, similarity);
 54
 86555        bool thresholdCheck = similarity >= threshold;
 56
 86557        if(withinThreshold != thresholdCheck)
 058        {
 059            withinThreshold = thresholdCheck;
 60
 061            if(withinThreshold)
 062            {
 063                OnBegin.Invoke(this);
 064            }
 65            else
 066            {
 067                OnEnd.Invoke(this);
 068            }
 069        }
 86570    }
 71
 72    public void OnReleased()
 073    {
 074        throw new NotImplementedException();
 75    }
 76}