< Summary

Class:OnTilt
Assembly:Test
File(s):E:/Unity/Unity Project/VR-Room/Assets/_Course Library/Scripts/Test/OnTilt.cs
Covered lines:20
Uncovered lines:3
Coverable lines:23
Total lines:78
Line coverage:86.9% (20 of 23)
Covered branches:0
Total branches:0
Covered methods:3
Total methods:3
Method coverage:100% (3 of 3)

Coverage History

Metrics

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

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    [ExcludeFromCodeCoverage]
 32    public void OnReleased()
 33    {
 34    }
 35
 36    [Tooltip("Tilt range, 0 - 180 degrees")]
 237    [Range(0, 1)] public float threshold = 0.1f;
 38
 39    [Serializable] public class TiltEvent : UnityEvent<MonoBehaviour> { }
 40
 41    // Threshold has been broken
 242    public TiltEvent OnBegin = new TiltEvent();
 43
 44    // Threshold is no longer broken
 245    public TiltEvent OnEnd = new TiltEvent();
 46
 247    private bool withinThreshold = false;
 48
 49    private void Update()
 923750    {
 923751        CheckOrientation();
 923752    }
 53
 54    private void CheckOrientation()
 923755    {
 923756        float similarity = Vector3.Dot(-transform.up, Vector3.up);
 923757        similarity = Mathf.InverseLerp(0, 1, similarity);
 58
 923759        bool thresholdCheck = similarity >= threshold;
 60
 923761        if(withinThreshold != thresholdCheck)
 162        {
 163            withinThreshold = thresholdCheck;
 64
 165            if(withinThreshold)
 166            {
 167                OnBegin.Invoke(this);
 168            }
 69            else
 070            {
 071                OnEnd.Invoke(this);
 072            }
 173        }
 923774    }
 75
 76
 77
 78}

Methods/Properties

OnTilt()
Update()
CheckOrientation()