< Summary

Class:DCL.Helpers.RaycastHandler
Assembly:MainScripts
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/PhysicsCast/RaycastHandler.cs
Covered lines:20
Uncovered lines:17
Coverable lines:37
Total lines:84
Line coverage:54% (20 of 37)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
SetHitInfo(...)0%110100%
Raycast(...)0%220100%
Raycast(...)0%220100%
RaycastAll(...)0%12300%
SetRaycastInfoData(...)0%27.1510044.44%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/PhysicsCast/RaycastHandler.cs

#LineLine coverage
 1using DCL.Components;
 2using DCL.Controllers;
 3using UnityEngine;
 4
 5namespace DCL.Helpers
 6{
 7    public class RaycastHandler : IRaycastHandler
 8    {
 9        private void SetHitInfo(ref HitInfo hitInfo, RaycastHit hit, IParcelScene scene)
 10        {
 2611            hitInfo.point = WorldStateUtils.ConvertUnityToScenePosition(hit.point, scene);
 2612            hitInfo.distance = hit.distance;
 2613            hitInfo.normal = hit.normal;
 2614            hitInfo.collider = hit.collider;
 2615        }
 16
 17        private bool Raycast(Ray ray, out HitInfo hitInfo, float distance, LayerMask layerMask, IParcelScene scene)
 18        {
 19            RaycastHit hit;
 2820            hitInfo = new HitInfo();
 21
 2822            if (Physics.Raycast(ray, out hit, distance, layerMask))
 23            {
 2624                SetHitInfo(ref hitInfo, hit, scene);
 2625                return true;
 26            }
 27
 228            return false;
 29        }
 30
 31        public RaycastResultInfo Raycast(Ray ray, float distance, LayerMask layerMaskTarget, IParcelScene scene)
 32        {
 2833            RaycastResultInfo raycastInfo = new RaycastResultInfo();
 34
 2835            raycastInfo.ray = ray;
 2836            raycastInfo.hitInfo = new RaycastHitInfo();
 37
 2838            if (Raycast(raycastInfo.ray, out raycastInfo.hitInfo.hit, distance, layerMaskTarget, scene))
 39            {
 2640                SetRaycastInfoData(ref raycastInfo.hitInfo, scene);
 41            }
 42
 2843            return raycastInfo;
 44        }
 45
 46        public RaycastResultInfoList RaycastAll(Ray ray, float distance, LayerMask layerMaskTarget, IParcelScene scene)
 47        {
 048            RaycastResultInfoList raycastInfo = new RaycastResultInfoList();
 049            raycastInfo.ray = ray;
 50
 051            RaycastHit[] result = Physics.RaycastAll(raycastInfo.ray, distance, layerMaskTarget);
 52
 053            if (result != null)
 54            {
 055                raycastInfo.hitInfo = new RaycastHitInfo[result.Length];
 056                int count = result.Length;
 57
 058                for (int i = 0; i < count; i++)
 59                {
 060                    raycastInfo.hitInfo[i] = new RaycastHitInfo();
 061                    raycastInfo.hitInfo[i].hit = new HitInfo();
 062                    SetHitInfo(ref raycastInfo.hitInfo[i].hit, result[i], scene);
 063                    SetRaycastInfoData(ref raycastInfo.hitInfo[i], scene);
 64                }
 65            }
 66
 067            return raycastInfo;
 68        }
 69
 70        private void SetRaycastInfoData(ref RaycastHitInfo hitInfo, IParcelScene scene)
 71        {
 2672            if (hitInfo.hit.collider == null)
 073                return;
 74
 2675            if (!CollidersManager.i.GetColliderInfo(hitInfo.hit.collider, out ColliderInfo info))
 076                return;
 77
 2678            if (scene != null)
 2679                hitInfo.isValid = (info.scene == scene) || (scene is GlobalScene globalScene && globalScene.isPortableEx
 080            else if (scene == null && WorldStateUtils.IsCharacterInsideScene(info.scene))
 081                hitInfo.isValid = true;
 082        }
 83    }
 84}