private static bool HandleMainLimits(HingeJoint2D hingeJoint2D, AnchorInfo anchorInfo, Color limitAreaColor, float limitDifference, Vector2 anchorPosition, float distanceFromCenter, float maxMainAngle, HingeJoint2DSettings settings, Color limitColor, float minMainAngle, Color angleWidgetColor, Color activeAngleColor, Color hoverAngleColor, float angleHandleSize, JointAngleLimits2D limits, float liveMainAngle) { var changed = false; using (new HandleColor(limitAreaColor)) { if (limitDifference > 360) { Handles.DrawSolidDisc(anchorPosition, Vector3.forward, distanceFromCenter); } else { Handles.DrawSolidArc(anchorPosition, Vector3.forward, Helpers2D.GetDirection(maxMainAngle + settings.mainAngleOffset), limitDifference, distanceFromCenter); } } using (new HandleColor(limitColor)) { Vector3 minMainEnd = anchorPosition + Helpers2D.GetDirection(minMainAngle + settings.mainAngleOffset) * distanceFromCenter; Handles.DrawLine(anchorPosition, minMainEnd); Vector3 maxMainEnd = anchorPosition + Helpers2D.GetDirection(maxMainAngle + settings.mainAngleOffset) * distanceFromCenter; Handles.DrawLine(anchorPosition, maxMainEnd); if (limitDifference > 360) { Handles.DrawWireDisc(anchorPosition, Vector3.forward, distanceFromCenter); } else { Handles.DrawWireArc(anchorPosition, Vector3.forward, Helpers2D.GetDirection(maxMainAngle + settings.mainAngleOffset), limitDifference, distanceFromCenter); } EditorGUI.BeginChangeCheck(); using ( HandleDrawerBase drawer = new HandleCircleDrawer(angleWidgetColor, activeAngleColor, hoverAngleColor)) { minMainAngle = EditorHelpers.AngleSlider(anchorInfo.GetControlID("lowerMainAngle"), drawer, anchorPosition, minMainAngle + settings.mainAngleOffset, distanceFromCenter, angleHandleSize * HandleUtility.GetHandleSize(minMainEnd) / 64) - settings.mainAngleOffset; } if (EditorGUI.EndChangeCheck()) { EditorHelpers.RecordUndo("Change Angle Limits", hingeJoint2D); limits.min = Handles.SnapValue(liveMainAngle - minMainAngle, editorSettings.snapAngle); hingeJoint2D.limits = limits; changed = true; } EditorGUI.BeginChangeCheck(); using ( HandleDrawerBase drawer = new HandleCircleDrawer(angleWidgetColor, activeAngleColor, hoverAngleColor)) { maxMainAngle = EditorHelpers.AngleSlider(anchorInfo.GetControlID("upperMainAngle"), drawer, anchorPosition, maxMainAngle + settings.mainAngleOffset, distanceFromCenter, angleHandleSize * HandleUtility.GetHandleSize(maxMainEnd) / 64) - settings.mainAngleOffset; } if (EditorGUI.EndChangeCheck()) { EditorHelpers.RecordUndo("Change Angle Limits", hingeJoint2D); limits.max = Handles.SnapValue(liveMainAngle - maxMainAngle, editorSettings.snapAngle); hingeJoint2D.limits = limits; changed = true; } } return(changed); }
private static bool HandleMainLimits(HingeJoint2D hingeJoint2D, AnchorInfo anchorInfo, Color limitAreaColor, float limitDifference, Vector2 anchorPosition, float distanceFromCenter, float maxMainAngle, HingeJoint2DSettings settings, Color limitColor, float minMainAngle, Color angleWidgetColor, Color activeAngleColor, Color hoverAngleColor, float angleHandleSize, JointAngleLimits2D limits, float liveMainAngle) { var changed = false; using (new HandleColor(limitAreaColor)) { if (limitDifference > 360) { Handles.DrawSolidDisc(anchorPosition, Vector3.forward, distanceFromCenter); } else { Handles.DrawSolidArc(anchorPosition, Vector3.forward, Helpers2D.GetDirection(maxMainAngle + settings.mainAngleOffset), limitDifference, distanceFromCenter); } } using (new HandleColor(limitColor)) { Vector3 minMainEnd = anchorPosition + Helpers2D.GetDirection(minMainAngle + settings.mainAngleOffset) * distanceFromCenter; Handles.DrawLine(anchorPosition, minMainEnd); Vector3 maxMainEnd = anchorPosition + Helpers2D.GetDirection(maxMainAngle + settings.mainAngleOffset) * distanceFromCenter; Handles.DrawLine(anchorPosition, maxMainEnd); if (limitDifference > 360) { Handles.DrawWireDisc(anchorPosition, Vector3.forward, distanceFromCenter); } else { Handles.DrawWireArc(anchorPosition, Vector3.forward, Helpers2D.GetDirection(maxMainAngle + settings.mainAngleOffset), limitDifference, distanceFromCenter); } EditorGUI.BeginChangeCheck(); using ( HandleDrawerBase drawer = new HandleCircleDrawer(angleWidgetColor, activeAngleColor, hoverAngleColor)) { minMainAngle = EditorHelpers.AngleSlider(anchorInfo.GetControlID("lowerMainAngle"), drawer, anchorPosition, minMainAngle + settings.mainAngleOffset, distanceFromCenter, angleHandleSize * HandleUtility.GetHandleSize(minMainEnd) / 64) - settings.mainAngleOffset; } if (EditorGUI.EndChangeCheck()) { EditorHelpers.RecordUndo("Change Angle Limits", hingeJoint2D); limits.min = Handles.SnapValue(liveMainAngle - minMainAngle, editorSettings.snapAngle); hingeJoint2D.limits = limits; changed = true; } EditorGUI.BeginChangeCheck(); using ( HandleDrawerBase drawer = new HandleCircleDrawer(angleWidgetColor, activeAngleColor, hoverAngleColor)) { maxMainAngle = EditorHelpers.AngleSlider(anchorInfo.GetControlID("upperMainAngle"), drawer, anchorPosition, maxMainAngle + settings.mainAngleOffset, distanceFromCenter, angleHandleSize * HandleUtility.GetHandleSize(maxMainEnd) / 64) - settings.mainAngleOffset; } if (EditorGUI.EndChangeCheck()) { EditorHelpers.RecordUndo("Change Angle Limits", hingeJoint2D); limits.max = Handles.SnapValue(liveMainAngle - maxMainAngle, editorSettings.snapAngle); hingeJoint2D.limits = limits; changed = true; } } return changed; }