< Summary

Class:OnVelocity
Assembly:Test
File(s):E:/Unity/Unity Project/VR-Room/Assets/_Course Library/Scripts/Test/OnVelocity.cs
Covered lines:32
Uncovered lines:5
Coverable lines:37
Total lines:77
Line coverage:86.4% (32 of 37)
Covered branches:0
Total branches:0
Covered methods:6
Total methods:7
Method coverage:85.7% (6 of 7)

Coverage History

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
OnVelocity()0%000100%
Awake()0%000100%
Update()0%000100%
CheckVelocity()0%00083.33%
HasVelocityBegun(...)0%000100%
HasVelcoityEnded(...)0%00087.5%
Reset()0%0000%

File(s)

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

#LineLine coverage
 1using System;
 2using UnityEngine;
 3using UnityEngine.Events;
 4
 5/// <summary>
 6/// Calls events for when the velocity of this objects breaks the begin and end threshold
 7/// </summary>
 8[RequireComponent(typeof(Rigidbody))]
 9public class OnVelocity : MonoBehaviour
 10{
 11    [Tooltip("The speed calls the begin event")]
 812    public float beginThreshold = 1.25f;
 13
 14    [Tooltip("The speed calls the end event")]
 815    public float endThreshold = 0.25f;
 16
 17    [Serializable] public class VelocityEvent : UnityEvent<MonoBehaviour> { }
 18
 19    // Begin threshold has been broken
 820    public VelocityEvent OnBegin = new VelocityEvent();
 21
 22    // End threshold has been broken
 823    public VelocityEvent OnEnd = new VelocityEvent();
 24
 825    private Rigidbody rigidBody = null;
 826    private bool hasBegun = false;
 27
 28    private void Awake()
 429    {
 430        rigidBody = GetComponent<Rigidbody>();
 431    }
 32
 33    private void Update()
 1115834    {
 1115835        CheckVelocity();
 1115836    }
 37
 38    private void CheckVelocity()
 1115839    {
 1115840        float speed = rigidBody.velocity.magnitude;
 1115841        hasBegun = HasVelocityBegun(speed);
 42
 1115843        if (HasVelcoityEnded(speed))
 044            Reset();
 1115845    }
 46
 47    private bool HasVelocityBegun(float speed)
 1115848    {
 1115849        if (hasBegun)
 207850            return true;
 51
 908052        bool beginCheck = speed > beginThreshold;
 53
 908054        if (beginCheck)
 255            OnBegin.Invoke(this);
 56
 908057        return beginCheck;
 1115858    }
 59
 60    private bool HasVelcoityEnded(float speed)
 1115861    {
 1115862        if (!hasBegun)
 907863            return false;
 64
 208065        bool endCheck = speed < endThreshold;
 66
 208067        if (endCheck)
 068            OnEnd.Invoke(this);
 69
 208070        return endCheck;
 1115871    }
 72
 73    public void Reset()
 074    {
 075        hasBegun = false;
 076    }
 77}