UnityEditor.RectTool.DistanceToRectangle C# (CSharp) Method

DistanceToRectangle() private static method

private static DistanceToRectangle ( Vector2 screenPoints, Vector2 mousePos ) : float
screenPoints Vector2
mousePos Vector2
return float
        private static unsafe float DistanceToRectangle(Vector2[] screenPoints, Vector2 mousePos)
        {
            bool flag = false;
            int num = 4;
            for (int i = 0; i < 5; i++)
            {
                Vector3 vector = *((Vector3*) &(screenPoints[i % 4]));
                Vector3 vector2 = *((Vector3*) &(screenPoints[num % 4]));
                if (((vector.y > mousePos.y) != (vector2.y > mousePos.y)) && (mousePos.x < ((((vector2.x - vector.x) * (mousePos.y - vector.y)) / (vector2.y - vector.y)) + vector.x)))
                {
                    flag = !flag;
                }
                num = i;
            }
            if (!flag)
            {
                float num4 = -1f;
                for (int j = 0; j < 4; j++)
                {
                    Vector3 a = *((Vector3*) &(screenPoints[j]));
                    Vector3 b = *((Vector3*) &(screenPoints[(j + 1) % 4]));
                    float num3 = DistancePointToLineSegment(mousePos, a, b);
                    if ((num3 < num4) || (num4 < 0f))
                    {
                        num4 = num3;
                    }
                }
                return num4;
            }
            return 0f;
        }

Usage Example

示例#1
0
 private static float SceneViewDistanceToRectangle(Vector3[] worldPoints, Vector2 mousePos)
 {
     Vector2[] array = new Vector2[4];
     for (int i = 0; i < 4; i++)
     {
         array[i] = HandleUtility.WorldToGUIPoint(worldPoints[i]);
     }
     return(RectTool.DistanceToRectangle(array, mousePos));
 }
All Usage Examples Of UnityEditor.RectTool::DistanceToRectangle