Ejemplo n.º 1
0
        private void HitAll(RaycastQuery query)
        {
            WebInterface.RaycastHitEntities raycastHitEntities = new WebInterface.RaycastHitEntities();

            IParcelScene scene = null;

            Environment.i.world.state.TryGetScene(query.sceneId, out scene);

            RaycastResultInfoList raycastResults = raycastHandler.RaycastAll(GetUnityRayFromQuery(query), query.ray.distance, ~layerMaskTarget, scene);

            raycastHitEntities.ray = GetRayInfoFromQuery(query);

            if (raycastResults.hitInfo != null && raycastResults.hitInfo.Length > 0)
            {
                int count = raycastResults.hitInfo.Length;
                List <WebInterface.RaycastHitEntity> hitEntityInfoList = new List <WebInterface.RaycastHitEntity>();

                for (int i = 0; i < count; i++)
                {
                    var hitInfo = raycastResults.hitInfo[i];
                    CollidersManager.i.GetColliderInfo(hitInfo.hit.collider, out ColliderInfo colliderInfo);

                    if (hitInfo.isValid)
                    {
                        WebInterface.RaycastHitEntity hitEntity = new WebInterface.RaycastHitEntity();
                        hitEntity.didHit          = true;
                        hitEntity.ray             = raycastHitEntities.ray;
                        hitEntity.hitPoint        = hitInfo.hit.point;
                        hitEntity.hitNormal       = hitInfo.hit.normal;
                        hitEntity.entity          = new WebInterface.HitEntityInfo();
                        hitEntity.entity.entityId = colliderInfo.entity != null ? colliderInfo.entity.entityId : null;
                        hitEntity.entity.meshName = colliderInfo.meshName;
                        hitEntityInfoList.Add(hitEntity);
                    }
                }

                raycastHitEntities.didHit    = true;
                raycastHitEntities.hitPoint  = raycastResults.hitInfo[0].hit.point;
                raycastHitEntities.hitNormal = raycastResults.hitInfo[0].hit.normal;
                raycastHitEntities.entities  = hitEntityInfoList.ToArray();
            }

            WebInterface.ReportRaycastHitAllResult(query.sceneId, query.id, query.raycastType, raycastHitEntities);
        }