コード例 #1
0
        public bool RaycastAllObjectsSorted(Ray ray, SceneRaycastPrecision raycastPresicion, List <GameObjectRayHit> hits)
        {
            bool anyHit = RaycastAllObjects(ray, raycastPresicion, hits);

            GameObjectRayHit.SortByHitDistance(hits);

            return(anyHit);
        }
コード例 #2
0
        public List <GameObjectRayHit> RaycastAllObjectsSorted(Ray ray, SceneRaycastPrecision raycastPresicion)
        {
            List <GameObjectRayHit> allHits = RaycastAllObjects(ray, raycastPresicion);

            GameObjectRayHit.SortByHitDistance(allHits);

            return(allHits);
        }
コード例 #3
0
        public SceneRaycastHit Raycast(Ray ray, SceneRaycastPrecision rtRaycastPrecision, SceneRaycastFilter raycastFilter)
        {
            List <GameObjectRayHit> allObjectHits    = RaycastAllObjectsSorted(ray, rtRaycastPrecision, raycastFilter);
            GameObjectRayHit        closestObjectHit = allObjectHits.Count != 0 ? allObjectHits[0] : null;
            XZGridRayHit            gridRayHit       = RaycastSceneGridIfVisible(ray);

            return(new SceneRaycastHit(closestObjectHit, gridRayHit));
        }
コード例 #4
0
        public SceneRaycastHit Raycast(Ray ray, SceneRaycastPrecision rtRaycastPrecision, SceneRaycastFilter raycastFilter)
        {
            RaycastAllObjectsSorted(ray, rtRaycastPrecision, raycastFilter, _objectHitBuffer);
            GameObjectRayHit closestObjectHit = _objectHitBuffer.Count != 0 ? _objectHitBuffer[0] : null;
            XZGridRayHit     gridRayHit       = RaycastSceneGridIfVisible(ray);

            return(new SceneRaycastHit(closestObjectHit, gridRayHit));
        }
コード例 #5
0
        public List <GameObjectRayHit> RaycastAllObjectsSorted(Ray ray, SceneRaycastPrecision rtRaycastPrecision, SceneRaycastFilter raycastFilter)
        {
            if (raycastFilter.AllowedObjectTypes.Count == 0)
            {
                return(new List <GameObjectRayHit>());
            }

            List <GameObjectRayHit> sortedHits = RaycastAllObjectsSorted(ray, rtRaycastPrecision);

            raycastFilter.FilterHits(sortedHits);

            return(sortedHits);
        }
コード例 #6
0
        public bool RaycastAllObjectsSorted(Ray ray, SceneRaycastPrecision rtRaycastPrecision, SceneRaycastFilter raycastFilter, List <GameObjectRayHit> hits)
        {
            hits.Clear();
            if (raycastFilter != null && raycastFilter.AllowedObjectTypes.Count == 0)
            {
                return(false);
            }

            RaycastAllObjectsSorted(ray, rtRaycastPrecision, hits);
            if (raycastFilter != null)
            {
                raycastFilter.FilterHits(hits);
            }

            return(hits.Count != 0);
        }
コード例 #7
0
        public bool RaycastAllObjects(Ray ray, SceneRaycastPrecision rtRaycastPrecision, List <GameObjectRayHit> hits)
        {
            if (Settings.PhysicsMode == ScenePhysicsMode.UnityColliders)
            {
                hits.Clear();
                RaycastHit[]   hits3D = Physics.RaycastAll(ray, float.MaxValue);
                RaycastHit2D[] hits2D = Physics2D.GetRayIntersectionAll(ray, float.MaxValue);
                GameObjectRayHit.Store(ray, hits2D, hits3D, hits);

                return(hits.Count != 0);
            }
            else
            {
                return(_sceneTree.RaycastAll(ray, rtRaycastPrecision, hits));
            }
        }
コード例 #8
0
        public List <GameObjectRayHit> RaycastAllObjects(Ray ray, SceneRaycastPrecision rtRaycastPrecision)
        {
            if (Settings.PhysicsMode == ScenePhysicsMode.UnityColliders)
            {
                RaycastHit[]   hits3D = Physics.RaycastAll(ray, float.MaxValue);
                RaycastHit2D[] hits2D = Physics2D.GetRayIntersectionAll(ray, float.MaxValue);

                List <GameObjectRayHit> allHits = new List <GameObjectRayHit>(GameObjectRayHit.Create(ray, hits3D));
                allHits.AddRange(GameObjectRayHit.Create(ray, hits2D));

                return(allHits);
            }
            else
            {
                return(_sceneTree.RaycastAll(ray, rtRaycastPrecision));
            }
        }
コード例 #9
0
        public bool RaycastAll(Ray ray, SceneRaycastPrecision raycastPresicion, List <GameObjectRayHit> hits)
        {
            hits.Clear();
            if (!_objectTree.RaycastAll(ray, _nodeHitBuffer))
            {
                return(false);
            }

            var boundsQConfig = new ObjectBounds.QueryConfig();

            boundsQConfig.ObjectTypes  = GameObjectTypeHelper.AllCombined;
            boundsQConfig.NoVolumeSize = Vector3Ex.FromValue(_nonMeshObjectSize);

            Vector3 camLook = RTFocusCamera.Get.Look;

            if (raycastPresicion == SceneRaycastPrecision.BestFit)
            {
                foreach (var nodeHit in _nodeHitBuffer)
                {
                    GameObject sceneObject = nodeHit.HitNode.Data;
                    if (sceneObject == null || !sceneObject.activeInHierarchy)
                    {
                        continue;
                    }

                    Renderer renderer = sceneObject.GetComponent <Renderer>();
                    if (renderer != null && !renderer.isVisible)
                    {
                        continue;
                    }

                    GameObjectType objectType = sceneObject.GetGameObjectType();
                    if (objectType == GameObjectType.Mesh)
                    {
                        GameObjectRayHit objectHit = RaycastMeshObject(ray, sceneObject);
                        if (objectHit != null)
                        {
                            hits.Add(objectHit);
                        }
                    }
                    else
                    if (objectType == GameObjectType.Terrain)
                    {
                        TerrainCollider terrainCollider = sceneObject.GetComponent <TerrainCollider>();
                        if (terrainCollider != null)
                        {
                            RaycastHit hitInfo;
                            if (terrainCollider.Raycast(ray, out hitInfo, float.MaxValue))
                            {
                                hits.Add(new GameObjectRayHit(ray, hitInfo));
                            }
                        }
                    }
                    else
                    if (objectType == GameObjectType.Sprite)
                    {
                        GameObjectRayHit objectHit = RaycastSpriteObject(ray, sceneObject);
                        if (objectHit != null)
                        {
                            hits.Add(objectHit);
                        }
                    }
                    else
                    {
                        OBB worldOBB = ObjectBounds.CalcWorldOBB(sceneObject, boundsQConfig);
                        if (worldOBB.IsValid)
                        {
                            float t;
                            if (BoxMath.Raycast(ray, out t, worldOBB.Center, worldOBB.Size, worldOBB.Rotation))
                            {
                                var faceDesc = BoxMath.GetFaceClosestToPoint(ray.GetPoint(t), worldOBB.Center, worldOBB.Size, worldOBB.Rotation, camLook);
                                var hit      = new GameObjectRayHit(ray, sceneObject, faceDesc.Plane.normal, t);
                                hits.Add(hit);
                            }
                        }
                    }
                }
            }
            else
            if (raycastPresicion == SceneRaycastPrecision.Box)
            {
                foreach (var nodeHit in _nodeHitBuffer)
                {
                    GameObject sceneObject = nodeHit.HitNode.Data;
                    if (sceneObject == null || !sceneObject.activeInHierarchy)
                    {
                        continue;
                    }

                    Renderer renderer = sceneObject.GetComponent <Renderer>();
                    if (renderer != null && !renderer.isVisible)
                    {
                        continue;
                    }

                    OBB worldOBB = ObjectBounds.CalcWorldOBB(sceneObject, boundsQConfig);
                    if (worldOBB.IsValid)
                    {
                        float t;
                        if (BoxMath.Raycast(ray, out t, worldOBB.Center, worldOBB.Size, worldOBB.Rotation))
                        {
                            var faceDesc = BoxMath.GetFaceClosestToPoint(ray.GetPoint(t), worldOBB.Center, worldOBB.Size, worldOBB.Rotation, camLook);
                            var hit      = new GameObjectRayHit(ray, sceneObject, faceDesc.Plane.normal, t);
                            hits.Add(hit);
                        }
                    }
                }
            }

            return(hits.Count != 0);
        }
コード例 #10
0
 public List <GameObjectRayHit> RaycastAllObjects(Ray ray, SceneRaycastPrecision rtRaycastPrecision)
 {
     return(_sceneTree.RaycastAll(ray, rtRaycastPrecision));
 }