< Summary

Class:DCL.PhysicsCast
Assembly:MainScripts
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/PhysicsCast/PhysicsCast.cs
Covered lines:0
Uncovered lines:57
Coverable lines:57
Total lines:143
Line coverage:0% (0 of 57)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
PhysicsCast()0%2100%
Query(...)0%12300%
HitFirst(...)0%20400%
HitAll(...)0%56700%
HitFirstAvatar(...)0%2100%
HitAllAvatars(...)0%2100%
GetUnityRayFromQuery(...)0%2100%
GetRayInfoFromQuery(...)0%2100%

File(s)

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

#LineLine coverage
 1using DCL.Helpers;
 2using DCL.Interface;
 3using DCL.Models;
 4using System.Collections.Generic;
 5using DCL.Components;
 6using DCL.Controllers;
 7using UnityEngine;
 8
 9namespace DCL
 10{
 11    public class PhysicsCast : Singleton<PhysicsCast>
 12    {
 13        private LayerMask layerMaskTarget;
 14
 15        private IRaycastHandler raycastHandler;
 16
 017        public PhysicsCast()
 18        {
 019            layerMaskTarget = 1 << LayerMask.NameToLayer("OnPointerEvent");
 020            raycastHandler = new RaycastHandler();
 021        }
 22
 23        public void Query(RaycastQuery query)
 24        {
 025            switch (query.raycastType)
 26            {
 27                case RaycastType.HIT_FIRST:
 028                    HitFirst(query);
 029                    break;
 30                case RaycastType.HIT_ALL:
 031                    HitAll(query);
 32                    break;
 33            }
 034        }
 35
 36        private void HitFirst(RaycastQuery query)
 37        {
 38            WebInterface.RaycastHitEntity hitEntity;
 39
 040            Environment.i.world.state.TryGetScene(query.sceneId, out IParcelScene scene);
 41
 042            RaycastResultInfo raycastInfo = raycastHandler.Raycast(GetUnityRayFromQuery(query), query.ray.distance, ~lay
 043            WebInterface.RayInfo rayInfo = GetRayInfoFromQuery(query);
 44
 045            if (raycastInfo != null)
 46            {
 047                CollidersManager.i.GetColliderInfo(raycastInfo.hitInfo.hit.collider, out ColliderInfo colliderInfo);
 48
 049                hitEntity = new WebInterface.RaycastHitEntity()
 50                {
 51                    didHit = raycastInfo.hitInfo.isValid,
 52                    hitNormal = raycastInfo.hitInfo.hit.normal,
 53                    hitPoint = raycastInfo.hitInfo.hit.point,
 54                    ray = rayInfo,
 55                    entity = new WebInterface.HitEntityInfo()
 56                    {
 57                        entityId = colliderInfo.entity != null ? colliderInfo.entity.entityId : null,
 58                        meshName = colliderInfo.meshName
 59                    }
 60                };
 061            }
 62            else
 63            {
 064                hitEntity = new WebInterface.RaycastHitEntity()
 65                {
 66                    didHit = false,
 67                    ray = rayInfo
 68                };
 69            }
 70
 071            WebInterface.ReportRaycastHitFirstResult(query.sceneId, query.id, query.raycastType, hitEntity);
 072        }
 73
 74        private void HitAll(RaycastQuery query)
 75        {
 076            WebInterface.RaycastHitEntities raycastHitEntities = new WebInterface.RaycastHitEntities();
 77
 078            IParcelScene scene = null;
 079            Environment.i.world.state.TryGetScene(query.sceneId, out scene);
 80
 081            RaycastResultInfoList raycastResults = raycastHandler.RaycastAll(GetUnityRayFromQuery(query), query.ray.dist
 82
 083            raycastHitEntities.ray = GetRayInfoFromQuery(query);
 84
 085            if (raycastResults.hitInfo != null && raycastResults.hitInfo.Length > 0)
 86            {
 087                int count = raycastResults.hitInfo.Length;
 088                List<WebInterface.RaycastHitEntity> hitEntityInfoList = new List<WebInterface.RaycastHitEntity>();
 89
 090                for (int i = 0; i < count; i++)
 91                {
 092                    var hitInfo = raycastResults.hitInfo[i];
 093                    CollidersManager.i.GetColliderInfo(hitInfo.hit.collider, out ColliderInfo colliderInfo);
 94
 095                    if (hitInfo.isValid)
 96                    {
 097                        WebInterface.RaycastHitEntity hitEntity = new WebInterface.RaycastHitEntity();
 098                        hitEntity.didHit = true;
 099                        hitEntity.ray = raycastHitEntities.ray;
 0100                        hitEntity.hitPoint = hitInfo.hit.point;
 0101                        hitEntity.hitNormal = hitInfo.hit.normal;
 0102                        hitEntity.entity = new WebInterface.HitEntityInfo();
 0103                        hitEntity.entity.entityId = colliderInfo.entity != null ? colliderInfo.entity.entityId : null;
 0104                        hitEntity.entity.meshName = colliderInfo.meshName;
 0105                        hitEntityInfoList.Add(hitEntity);
 106                    }
 107                }
 108
 0109                raycastHitEntities.didHit = true;
 0110                raycastHitEntities.hitPoint = raycastResults.hitInfo[0].hit.point;
 0111                raycastHitEntities.hitNormal = raycastResults.hitInfo[0].hit.normal;
 0112                raycastHitEntities.entities = hitEntityInfoList.ToArray();
 113            }
 114
 0115            WebInterface.ReportRaycastHitAllResult(query.sceneId, query.id, query.raycastType, raycastHitEntities);
 0116        }
 117
 0118        private void HitFirstAvatar(RaycastQuery query) { }
 119
 0120        private void HitAllAvatars(RaycastQuery query) { }
 121
 122        private UnityEngine.Ray GetUnityRayFromQuery(RaycastQuery query)
 123        {
 0124            UnityEngine.Ray ray = new UnityEngine.Ray();
 125
 0126            ray.origin = query.ray.unityOrigin;
 0127            ray.direction = query.ray.direction;
 128
 0129            return ray;
 130        }
 131
 132        private WebInterface.RayInfo GetRayInfoFromQuery(RaycastQuery query)
 133        {
 0134            WebInterface.RayInfo rayInfo = new WebInterface.RayInfo();
 135
 0136            rayInfo.direction = query.ray.direction;
 0137            rayInfo.distance = query.ray.distance;
 0138            rayInfo.origin = query.ray.origin;
 139
 0140            return rayInfo;
 141        }
 142    }
 143}