< Summary

Class:OnVelocity
Assembly:Test
File(s):D:/--UnityProject/VR/_____ISSTA 26/VR-Room/Assets/_Course Library/Scripts/Test/OnVelocity.cs
Covered lines:30
Uncovered lines:7
Coverable lines:37
Total lines:77
Line coverage:81% (30 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%00083.33%
HasVelocityBegun(...)0%00075%
HasVelcoityEnded(...)0%00050%
Reset()0%000100%

File(s)

D:/--UnityProject/VR/_____ISSTA 26/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")]
 412    public float beginThreshold = 1.25f;
 13
 14    [Tooltip("The speed calls the end event")]
 415    public float endThreshold = 0.25f;
 16
 17    [Serializable] public class VelocityEvent : UnityEvent<MonoBehaviour> { }
 18
 19    // Begin threshold has been broken
 420    public VelocityEvent OnBegin = new VelocityEvent();
 21
 22    // End threshold has been broken
 423    public VelocityEvent OnEnd = new VelocityEvent();
 24
 425    private Rigidbody rigidBody = null;
 426    private bool hasBegun = false;
 27
 28    private void Awake()
 229    {
 230        rigidBody = GetComponent<Rigidbody>();
 231    }
 32
 33    private void Update()
 1240634    {
 1240635        CheckVelocity();
 1240636    }
 37
 38    private void CheckVelocity()
 1240639    {
 1240640        float speed = rigidBody.velocity.magnitude;
 1240641        hasBegun = HasVelocityBegun(speed);
 42
 1240643        if (HasVelcoityEnded(speed))
 044            Reset();
 1240645    }
 46
 47    private bool HasVelocityBegun(float speed)
 1240648    {
 1240649        if (hasBegun)
 050            return true;
 51
 1240652        bool beginCheck = speed > beginThreshold;
 53
 1240654        if (beginCheck)
 055            OnBegin.Invoke(this);
 56
 1240657        return beginCheck;
 1240658    }
 59
 60    private bool HasVelcoityEnded(float speed)
 1240661    {
 1240662        if (!hasBegun)
 1240663            return false;
 64
 065        bool endCheck = speed < endThreshold;
 66
 067        if (endCheck)
 068            OnEnd.Invoke(this);
 69
 070        return endCheck;
 1240671    }
 72
 73    public void Reset()
 174    {
 175        hasBegun = false;
 176    }
 77}