示例#1
0
        public bool RaycastSceneMeshes(Ray ray, out RaycastHit hit, bool includeTerrain, bool includeColliders, bool includeMeshes)
        {
            hit = new RaycastHit();
            RaycastHit tempRaycastHit;
            bool       hitSomething = false;

            float minDistance = float.PositiveInfinity;

            if (includeTerrain && !includeColliders)
            {
                for (int i = 0; i <= SceneTerrainColliderList.Count - 1; i++)
                {
                    if (!SceneTerrainColliderList[i].Raycast(ray, out tempRaycastHit, float.PositiveInfinity))
                    {
                        continue;
                    }
                    float distance = Vector3.Distance(ray.origin, tempRaycastHit.point);
                    if (!(distance < minDistance))
                    {
                        continue;
                    }
                    minDistance  = distance;
                    hitSomething = true;
                    hit          = tempRaycastHit;
                }
            }

            if (includeColliders && !includeTerrain)
            {
                RaycastHit[] hits = Physics.RaycastAll(ray, float.PositiveInfinity);
                for (int i = 0; i <= hits.Length - 1; i++)
                {
                    if (!(hits[i].collider is TerrainCollider))
                    {
                        float distance = Vector3.Distance(ray.origin, hits[i].point);
                        if (distance < minDistance)
                        {
                            minDistance  = distance;
                            hitSomething = true;
                            hit          = hits[i];
                        }
                    }
                }
            }

            if (includeTerrain && includeColliders)
            {
                if (Physics.Raycast(ray, out tempRaycastHit, float.PositiveInfinity))
                {
                    float distance = Vector3.Distance(ray.origin, tempRaycastHit.point);
                    if (distance < minDistance)
                    {
                        minDistance  = distance;
                        hitSomething = true;
                        hit          = tempRaycastHit;
                    }
                }
            }

            if (includeMeshes)
            {
                List <MeshRendererRaycastInfo> collidingWith = new List <MeshRendererRaycastInfo>();
                BoundsOctree.GetColliding(collidingWith, ray);

                for (int i = 0; i <= collidingWith.Count - 1; i++)
                {
                    //enable for debug
                    //Gizmos.color = Color.white;
                    //Handles.DrawWireCube(collidingWith[i].Bounds.center, collidingWith[i].Bounds.size);

                    if (!IntersectRayMesh(ray, collidingWith[i].Mesh,
                                          collidingWith[i].LocalToWorldMatrix4X4, out tempRaycastHit))
                    {
                        continue;
                    }
                    float distance = Vector3.Distance(ray.origin, tempRaycastHit.point);
                    if (!(distance < minDistance))
                    {
                        continue;
                    }
                    minDistance  = distance;
                    hitSomething = true;
                    hit          = tempRaycastHit;
                }
            }

            return(hitSomething);
        }
示例#2
0
        protected override Cell GetCell_internal(Vector2 cellPosition)
        {
            var result = UnityOctreeCellTree.GetColliding(new Bounds(cellPosition, Vector3.zero));

            return(result.Count > 0 ? result[0] : null);
        }
示例#3
0
 public bool GetIntersections(Bounds bounds, out T[] intersections)
 {
     intersections = m_Octree.GetColliding(bounds);
     return(intersections.Length > 0);
 }
示例#4
0
 public bool GetIntersections(List <T> intersections, Bounds bounds)
 {
     m_Octree.GetColliding(intersections, bounds);
     return(intersections.Count > 0);
 }