/// <summary> /// Determine the distance from the mouse position to the screen space rectangle specified by the 4 points. /// </summary> static public float DistanceToRectangle(Vector2[] screenPoints, Vector2 mousePos) { bool oddNodes = false; int j = 4; for (int i = 0; i < 5; i++) { Vector3 v0 = screenPoints[WeaponXIMath.RepeatIndex(i, 4)]; Vector3 v1 = screenPoints[WeaponXIMath.RepeatIndex(j, 4)]; if ((v0.y > mousePos.y) != (v1.y > mousePos.y)) { if (mousePos.x < (v1.x - v0.x) * (mousePos.y - v0.y) / (v1.y - v0.y) + v0.x) { oddNodes = !oddNodes; } } j = i; } if (!oddNodes) { float dist, closestDist = -1f; for (int i = 0; i < 4; i++) { Vector3 v0 = screenPoints[i]; Vector3 v1 = screenPoints[WeaponXIMath.RepeatIndex(i + 1, 4)]; dist = DistancePointToLineSegment(mousePos, v0, v1); if (dist < closestDist || closestDist < 0f) { closestDist = dist; } } return(closestDist); } else { return(0f); } }
void DrawRotation() { GUILayout.BeginHorizontal(); { bool reset = GUILayout.Button("R", GUILayout.Width(20f)); Vector3 visible = (serializedObject.targetObject as Transform).localEulerAngles; visible.x = WeaponXIMath.WrapAngle(visible.x); visible.y = WeaponXIMath.WrapAngle(visible.y); visible.z = WeaponXIMath.WrapAngle(visible.z); Axes changed = CheckDifference(mRot); Axes altered = Axes.None; GUILayoutOption opt = GUILayout.MinWidth(30f); if (FloatField("X", ref visible.x, (changed & Axes.X) != 0, false, opt)) { altered |= Axes.X; } if (FloatField("Y", ref visible.y, (changed & Axes.Y) != 0, false, opt)) { altered |= Axes.Y; } if (FloatField("Z", ref visible.z, (changed & Axes.Z) != 0, false, opt)) { altered |= Axes.Z; } if (reset) { mRot.quaternionValue = Quaternion.identity; } else if (altered != Axes.None) { Undo.RecordObjects(serializedObject.targetObjects, "Change Rotation"); foreach (Object obj in serializedObject.targetObjects) { Transform t = obj as Transform; Vector3 v = t.localEulerAngles; if ((altered & Axes.X) != 0) { v.x = visible.x; } if ((altered & Axes.Y) != 0) { v.y = visible.y; } if ((altered & Axes.Z) != 0) { v.z = visible.z; } t.localEulerAngles = v; } } } GUILayout.EndHorizontal(); }