static private DistanceToRectangleInternal ( Vector3 position, |
||
position | Vector3 | |
rotation | ||
size | Vector2 | |
return | float |
internal static float DistanceToRectangleInternal(Vector3 position, Quaternion rotation, Vector2 size)
{
Vector3 vector = (Vector3) (rotation * new Vector3(size.x, 0f, 0f));
Vector3 vector2 = (Vector3) (rotation * new Vector3(0f, size.y, 0f));
points[0] = (Vector3) WorldToGUIPoint((position + vector) + vector2);
points[1] = (Vector3) WorldToGUIPoint((position + vector) - vector2);
points[2] = (Vector3) WorldToGUIPoint((position - vector) - vector2);
points[3] = (Vector3) WorldToGUIPoint((position - vector) + vector2);
points[4] = points[0];
Vector2 mousePosition = Event.current.mousePosition;
bool flag = false;
int index = 4;
for (int i = 0; i < 5; i++)
{
if (((points[i].y > mousePosition.y) != (points[index].y > mousePosition.y)) && (mousePosition.x < ((((points[index].x - points[i].x) * (mousePosition.y - points[i].y)) / (points[index].y - points[i].y)) + points[i].x)))
{
flag = !flag;
}
index = i;
}
if (!flag)
{
float num4 = -1f;
index = 1;
for (int j = 0; j < 4; j++)
{
float num3 = DistancePointToLineSegment(mousePosition, points[j], points[index++]);
if ((num3 < num4) || (num4 < 0f))
{
num4 = num3;
}
}
return num4;
}
return 0f;
}
private static void HandleCap(int controlID, Vector3 position, GUIStyle guiStyle, EventType eventType) { if (eventType != EventType.Layout) { if (eventType == EventType.Repaint) { Handles.BeginGUI(); position = HandleUtility.WorldToGUIPoint(position); float fixedWidth = guiStyle.fixedWidth; float fixedHeight = guiStyle.fixedHeight; Rect position2 = new Rect(position.x - fixedWidth / 2f, position.y - fixedHeight / 2f, fixedWidth, fixedHeight); guiStyle.Draw(position2, GUIContent.none, controlID); Handles.EndGUI(); } } else { HandleUtility.AddControl(controlID, HandleUtility.DistanceToRectangleInternal(position, Quaternion.identity, Vector2.zero)); } }