< Summary

Class:OnTilt
Assembly:Test
File(s):D:/--UnityProject/VR/VRExplorer_subjects/VR-Room/Assets/_Course Library/Scripts/Test/OnTilt.cs
Covered lines:23
Uncovered lines:0
Coverable lines:23
Total lines:72
Line coverage:100% (23 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%000100%

File(s)

D:/--UnityProject/VR/VRExplorer_subjects/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 VRExplorer;
 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
 26    [ExcludeFromCodeCoverage]
 27    public void OnGrabbed()
 28    {
 29    }
 30
 31    [Tooltip("Tilt range, 0 - 180 degrees")]
 532    [Range(0, 1)] public float threshold = 0.1f;
 33
 34    [Serializable] public class TiltEvent : UnityEvent<MonoBehaviour> { }
 35
 36    // Threshold has been broken
 537    public TiltEvent OnBegin = new TiltEvent();
 38
 39    // Threshold is no longer broken
 540    public TiltEvent OnEnd = new TiltEvent();
 41
 542    private bool withinThreshold = false;
 43
 44    private void Update()
 676745    {
 676746        CheckOrientation();
 676747    }
 48
 49    private void CheckOrientation()
 676750    {
 676751        float similarity = Vector3.Dot(-transform.up, Vector3.up);
 676752        similarity = Mathf.InverseLerp(0, 1, similarity);
 53
 676754        bool thresholdCheck = similarity >= threshold;
 55
 676756        if(withinThreshold != thresholdCheck)
 657        {
 658            withinThreshold = thresholdCheck;
 59
 660            if(withinThreshold)
 361            {
 362                OnBegin.Invoke(this);
 363            }
 64            else
 365            {
 366                OnEnd.Invoke(this);
 367            }
 668        }
 676769    }
 70
 71
 72}

Methods/Properties

OnTilt()
Update()
CheckOrientation()