Пример #1
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);
        }
Пример #2
0
        public static RaycastHit[] RaycastAll(Vector2 origin, Vector2 direction, float distance, int layerMask)
        {
#if DEBUG
            Application.raycastTimer.Start();
#endif

            RaycastHelper.SetValues(distance, false, layerMask);

            Vector2 pt2 = origin + (direction * distance);
            if (pt2 == origin)
            {
                return(new RaycastHit[0]);
            }
            world.RayCast(null, origin, pt2);
#if DEBUG
            Application.raycastTimer.Stop();
#endif
            return(RaycastHelper.Hits);
        }
Пример #3
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);
        }
Пример #4
0
        public static RaycastHit[] RaycastFromTo(Vector2 from, Vector2 to, int layerMask)
        {
#if DEBUG
            Application.raycastTimer.Start();
#endif
            if (from == to)
            {
                #if DEBUG
                Application.raycastTimer.Stop();
                #endif
                return(new RaycastHit[0]);
            }
            RaycastHelper.SetValues(100f, false, layerMask);

            world.RayCast(null, from, to);
#if DEBUG
            Application.raycastTimer.Stop();
#endif
            return(RaycastHelper.HitsByDistance);
        }