< Summary

Class:OnVelocity
Assembly:Test
File(s):D:/--UnityProject/VR/VRExplorer_subjects/VR-Room/Assets/_Course Library/Scripts/Test/OnVelocity.cs
Covered lines:37
Uncovered lines:0
Coverable lines:37
Total lines:77
Line coverage:100% (37 of 37)
Covered branches:0
Total branches:0
Covered methods:7
Total methods:7
Method coverage:100% (7 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%000100%
HasVelocityBegun(...)0%000100%
HasVelcoityEnded(...)0%000100%
Reset()0%000100%

File(s)

D:/--UnityProject/VR/VRExplorer_subjects/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")]
 1012    public float beginThreshold = 1.25f;
 13
 14    [Tooltip("The speed calls the end event")]
 1015    public float endThreshold = 0.25f;
 16
 17    [Serializable] public class VelocityEvent : UnityEvent<MonoBehaviour> { }
 18
 19    // Begin threshold has been broken
 1020    public VelocityEvent OnBegin = new VelocityEvent();
 21
 22    // End threshold has been broken
 1023    public VelocityEvent OnEnd = new VelocityEvent();
 24
 1025    private Rigidbody rigidBody = null;
 1026    private bool hasBegun = false;
 27
 28    private void Awake()
 829    {
 830        rigidBody = GetComponent<Rigidbody>();
 831    }
 32
 33    private void Update()
 1353434    {
 1353435        CheckVelocity();
 1353436    }
 37
 38    private void CheckVelocity()
 1353439    {
 1353440        float speed = rigidBody.velocity.magnitude;
 1353441        hasBegun = HasVelocityBegun(speed);
 42
 1353443        if (HasVelcoityEnded(speed))
 844            Reset();
 1353445    }
 46
 47    private bool HasVelocityBegun(float speed)
 1353448    {
 1353449        if (hasBegun)
 25750            return true;
 51
 1327752        bool beginCheck = speed > beginThreshold;
 53
 1327754        if (beginCheck)
 855            OnBegin.Invoke(this);
 56
 1327757        return beginCheck;
 1353458    }
 59
 60    private bool HasVelcoityEnded(float speed)
 1353461    {
 1353462        if (!hasBegun)
 1326963            return false;
 64
 26565        bool endCheck = speed < endThreshold;
 66
 26567        if (endCheck)
 868            OnEnd.Invoke(this);
 69
 26570        return endCheck;
 1353471    }
 72
 73    public void Reset()
 874    {
 875        hasBegun = false;
 876    }
 77}