< Summary

Class:GDX.CapsuleColliderExtensions
Assembly:GDX
File(s):D:/BuildAgent/work/GDX-Documentation/Projects/GDX_Development/Packages/com.dotbunny.gdx/GDX/CapsuleColliderExtensions.cs
Covered lines:0
Uncovered lines:19
Coverable lines:19
Total lines:67
Line coverage:0% (0 of 19)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:2
Method coverage:0% (0 of 2)

Coverage History

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Direction(...)0%12300%
OutSphereCenters(...)0%20400%

File(s)

D:/BuildAgent/work/GDX-Documentation/Projects/GDX_Development/Packages/com.dotbunny.gdx/GDX/CapsuleColliderExtensions.cs

#LineLine coverage
 1// Copyright (c) 2020-2022 dotBunny Inc.
 2// dotBunny licenses this file to you under the BSL-1.0 license.
 3// See the LICENSE file in the project root for more information.
 4
 5#if !UNITY_DOTSRUNTIME
 6
 7using System.Runtime.CompilerServices;
 8using UnityEngine;
 9
 10namespace GDX
 11{
 12    /// <summary>
 13    ///     <see cref="UnityEngine.CapsuleCollider" /> Based Extension Methods
 14    /// </summary>
 15    /// <exception cref="UnsupportedRuntimeException">Not supported on DOTS Runtime.</exception>
 16    [VisualScriptingCompatible(2)]
 17    public static class CapsuleColliderExtensions
 18    {
 19        /// <summary>
 20        ///     Get a <see cref="Vector3" /> based orientation of the <paramref name="targetCapsuleCollider"/>.
 21        /// </summary>
 22        /// <param name="targetCapsuleCollider">The capsule collider</param>
 23        /// <returns>The direction of a <see cref="CapsuleCollider"/> in its local space.</returns>
 24        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 25        public static Vector3 Direction(this CapsuleCollider targetCapsuleCollider)
 026        {
 027            int direction = targetCapsuleCollider.direction;
 028            if(direction == 0) return Vector3.right;
 029            return direction == 1 ? Vector3.up : Vector3.forward;
 030        }
 31
 32        /// <summary>
 33        ///     Return into <paramref name="topPosition"/> and <paramref name="bottomPosition"/>, the respective world-s
 34        /// </summary>
 35        /// <param name="targetCapsuleCollider">The <see cref="CapsuleCollider"/> having its spheres evaluated.</param>
 36        /// <param name="topPosition">The determined top spheres center position in world-space.</param>
 37        /// <param name="bottomPosition">The determined bottom spheres center position in world-space.</param>
 38        public static void OutSphereCenters(CapsuleCollider targetCapsuleCollider, out Vector3 topPosition, out Vector3 
 039        {
 40            // Bring it local
 041            Vector3 cachedCenter = targetCapsuleCollider.center;
 042            topPosition = cachedCenter;
 43
 44            // Calculate offset based on height/radius to center
 045            switch (targetCapsuleCollider.direction)
 46            {
 47                case 0:
 048                    topPosition.x = targetCapsuleCollider.height * 0.5f - targetCapsuleCollider.radius;
 049                    break;
 50                case 1:
 051                    topPosition.y = targetCapsuleCollider.height * 0.5f - targetCapsuleCollider.radius;
 052                    break;
 53                case 2:
 054                    topPosition.z = targetCapsuleCollider.height * 0.5f - targetCapsuleCollider.radius;
 055                    break;
 56            }
 57
 58            // Invert bottom because the top was positive, now we need negative
 059            bottomPosition = -topPosition;
 60
 61            // Convert positions to world-space
 062            topPosition = targetCapsuleCollider.transform.TransformPoint(topPosition);
 063            bottomPosition = targetCapsuleCollider.transform.TransformPoint(bottomPosition);
 064        }
 65    }
 66}
 67#endif