Ejemplo n.º 1
0
        //private static List<RaycastHit> hits = new List<RaycastHit>(ApplicationSettings.QueryHelperDefaultCapacity);
        internal static bool QueryCallback(Fixture fixture)
        {
            Component uo = fixture.Body.UserData;
            Collider coll = uo as Collider;

            if (coll == null && (uo is Rigidbody))
            {
                coll = (uo as Rigidbody).collider;
            }

            if ((bool)coll && fixture.Body.Enabled && coll.gameObject.active && (layermask & (1 << coll.gameObject.layer)) > 0)
            {
                colliders[colliderCount++] = coll;
                _hit = new RaycastHit() { body = fixture.Body, collider = coll, transform = coll.transform };
                if (breakOnFirst)
                {
                    return false;
                }
            }

            return true;
        }
Ejemplo n.º 2
0
 public static bool SphereCast(Vector3 origin, float radius, Vector3 direction, out RaycastHit hitInfo, float distance)
 {
     return SphereCast(origin, radius, direction, out hitInfo, distance, kDefaultRaycastLayers);
 }
Ejemplo n.º 3
0
 public static bool SphereCast(Vector3 origin, float radius, Vector3 direction, out RaycastHit hitInfo)
 {
     return SphereCast(origin, radius, direction, out hitInfo, Mathf.Infinity, kDefaultRaycastLayers);
 }
Ejemplo n.º 4
0
 public static bool Raycast(Ray ray, out RaycastHit hitInfo, float distance, int layerMask)
 {
     return Raycast(ray.origin, ray.direction, out hitInfo, distance, layerMask);
 }
Ejemplo n.º 5
0
 public static bool Raycast(Ray ray, out RaycastHit hitInfo, float distance)
 {
     return Raycast(ray.origin, ray.direction, out hitInfo, distance, kDefaultRaycastLayers);
 }
Ejemplo n.º 6
0
 public static bool Raycast(Ray ray, out RaycastHit hitInfo)
 {
     return Raycast(ray.origin, ray.direction, out hitInfo, Mathf.Infinity, kDefaultRaycastLayers);
 }
Ejemplo n.º 7
0
 public static bool Raycast(Vector3 origin, Vector3 direction, out RaycastHit hitInfo, float distance, int layerMask)
 {
     return Raycast((Vector2)origin, (Vector2)direction, out hitInfo, distance, layerMask);
 }
Ejemplo n.º 8
0
 public static bool Linecast(Vector3 start, Vector3 end, out RaycastHit hitInfo, int layerMask)
 {
     #if DEBUG
     Application.raycastTimer.Start();
     #endif
     Vector2 pt2 = end;
     Vector2 origin = start;
     RaycastHelper.SetValues((origin - pt2).magnitude, true, layerMask);
     if (pt2 == origin)
     {
         hitInfo = new RaycastHit();
         return false;
     }
     world.RayCast(null, origin, pt2);
     hitInfo = RaycastHelper.ClosestHit();
     #if DEBUG
     Application.raycastTimer.Stop();
     #endif
     return (RaycastHelper.HitCount > 0);
 }
Ejemplo n.º 9
0
 public static bool Raycast(Vector3 origin, Vector3 direction, out RaycastHit hitInfo)
 {
     return Raycast(origin, direction, out hitInfo, Mathf.Infinity, kDefaultRaycastLayers);
 }
Ejemplo n.º 10
0
        public static bool Raycast(Vector2 origin, Vector2 direction, out RaycastHit hitInfo, float distance, int layerMask)
        {
            #if DEBUG
            Application.raycastTimer.Start();
            #endif
            RaycastHelper.SetValues(distance, true, layerMask);

            Vector2 pt2 = origin + (direction * distance);
            if (pt2 == origin)
            {
                hitInfo = new RaycastHit();
                return false;
            }
            try
            {
                world.RayCast(null, origin, pt2);
                hitInfo = RaycastHelper.ClosestHit();
            }
            catch (InvalidOperationException)
            {
                hitInfo = new RaycastHit();
                Debug.Log("RAYCAST THREW InvalidOperationException");
                return false;
            }
            finally
            {
            #if DEBUG
                Application.raycastTimer.Stop();
            #endif
            }
            return (RaycastHelper.HitCount > 0);
        }
Ejemplo n.º 11
0
 public static RaycastHit[] PointcastAll(Vector2 point, int layerMask)
 {
     #if DEBUG
     Application.raycastTimer.Start();
     #endif
     fList.Clear();
     world.TestPointAllActive(point, fList, layerMask);
     RaycastHit[] hits = new RaycastHit[fList.Count];
     for (int i = 0; i < fList.Count; i++)
     {
         Fixture f = fList[i];
         RaycastHit hitInfo = new RaycastHit();
         hitInfo.body = f.Body;
         hitInfo.collider = f.Body.UserData;
         hitInfo.transform = f.Body.UserData.transform;
         hitInfo.point = VectorConverter.Convert(point, f.Body.UserData.to2dMode);
         hits[i] = hitInfo;
     }
     #if DEBUG
     Application.raycastTimer.Stop();
     #endif
     return hits;
 }
Ejemplo n.º 12
0
 public static bool Pointcast(Vector2 point, out RaycastHit hitInfo, int layerMask)
 {
     #if DEBUG
     Application.raycastTimer.Start();
     #endif
     Fixture f = world.TestPointActive(point, layerMask);
     hitInfo = new RaycastHit();
     if (f != null)
     {
         hitInfo.body = f.Body;
         hitInfo.collider = f.Body.UserData;
         hitInfo.transform = f.Body.UserData.transform;
         hitInfo.point = VectorConverter.Convert(point, f.Body.UserData.to2dMode);
     }
     #if DEBUG
     Application.raycastTimer.Stop();
     #endif
     return (f != null);
 }
Ejemplo n.º 13
0
 public static bool Pointcast(Vector2 point, out RaycastHit hitInfo)
 {
     return Pointcast(point, out hitInfo, kDefaultRaycastLayers);
 }
Ejemplo n.º 14
0
 public static bool Linecast(Vector3 start, Vector3 end, out RaycastHit hitInfo)
 {
     return Linecast(start, end, out hitInfo, kDefaultRaycastLayers);
 }
Ejemplo n.º 15
0
        public static bool SphereCast(Vector3 origin, float radius, Vector3 direction, out RaycastHit hitInfo, float distance, int layerMask)
        {
            Ray ray = new Ray(origin, direction);
            AABB aabb = new AABB(ray.GetPoint(distance / 2), distance, radius);
            QueryHelper.layermask = layerMask;
            QueryHelper.breakOnFirst = true;
            world.QueryAABB(null, ref aabb);

            if (QueryHelper.GetQueryResult().Length > 0)
            {
                hitInfo = QueryHelper.ClosestHit();
                return true;
            }
            hitInfo = new RaycastHit();
            return false;
        }
Ejemplo n.º 16
0
 internal static bool Raycast(Body body, Ray ray, out RaycastHit hitInfo, float distance)
 {
     RayCastOutput output;
     RayCastInput input = new RayCastInput() { Point1 = ray.origin, Point2 = ray.origin + ray.direction, MaxFraction = distance };
     hitInfo = new RaycastHit() { body = body };
     for (int i = 0; i < body.FixtureList.Count; i++)
     {
         if (body.FixtureList[i].RayCast(out output, ref input, 0))
         {
             hitInfo.collider = body.UserData;
             hitInfo.transform = body.UserData.transform;
             hitInfo.normal = VectorConverter.Convert(output.Normal, body.UserData.to2dMode);
             hitInfo.distance = output.Fraction;
             hitInfo.point = ray.GetPoint(output.Fraction);
             return true;
         }
     }
     return false;
 }
Ejemplo n.º 17
0
 public static bool Raycast(Vector3 origin, Vector3 direction, out RaycastHit hitInfo, float distance)
 {
     return Raycast(origin, direction, out hitInfo, distance, kDefaultRaycastLayers);
 }