public static float LineSlider(int controlID, Vector2 center, float distance, float angle, float handleScale = 1f, bool alwaysVisible = false, bool arrow = false) { var hoverState = StateObject.Get <HoverState>(controlID); var direction = Helpers2D.GetDirection(angle); var wantedPosition = center + direction * distance; var handleSize = HandleUtility.GetHandleSize(wantedPosition) * handleScale; var normal = Helpers2D.GetPerpendicularVector(direction) * handleSize; EditorGUI.BeginChangeCheck(); wantedPosition = Handles.Slider2D(controlID, wantedPosition, Vector3.forward, Vector3.up, Vector3.right, normal.magnitude * 2, (id, position, rotation, size) => { }, Vector2.zero); if (EditorGUI.EndChangeCheck()) { distance = Helpers2D.DistanceAlongLine(new Ray(center, direction), wantedPosition); } var current = Event.current; float drawScale = 1; switch (current.GetTypeForControl(controlID)) { case EventType.mouseMove: var hovering = HandleUtility.nearestControl == controlID; if (hoverState.hovering != hovering) { current.Use(); hoverState.hovering = hovering; } break; case EventType.repaint: var handleColor = Handles.color; if (GUIUtility.hotControl == controlID || hoverState.hovering) { if (GUIUtility.hotControl == controlID) { handleColor = Color.red; } else { handleColor = Color.yellow; } var cursor = RotatedResizeCursor(direction); SetEditorCursor(cursor, controlID); drawScale = 2; } else if (GUIUtility.hotControl != 0) { handleColor.a *= 0.5f; } var drawNormal = normal * drawScale; using (new HandleColor(handleColor)) { Vector3 a = wantedPosition - drawNormal; Vector3 b = wantedPosition + drawNormal; if (GUIUtility.hotControl == controlID) { var cameraVectorA = HandleToScreenPoint(a); var cameraVectorB = HandleToScreenPoint(b); cameraVectorA.z -= 0.01f; cameraVectorB.z -= 0.01f; a = ScreenToHandlePoint(cameraVectorA); b = ScreenToHandlePoint(cameraVectorB); } if (arrow) { Vector3 directionOffset = direction * handleSize * drawScale * 0.5f; var backgroundColor = Helpers.YIQ(Handles.color); backgroundColor.a = Handles.color.a; // using (new HandleColor(backgroundColor)) { DrawThickLine(a, b, 4, alwaysVisible); DrawThickLine(a - directionOffset, a, 4, alwaysVisible); DrawThickLine(b - directionOffset, b, 4, alwaysVisible); } DrawThickLine(a, b, 2, alwaysVisible); DrawThickLine(a - directionOffset, a, 2, alwaysVisible); DrawThickLine(b - directionOffset, b, 2, alwaysVisible); } else { DrawThickLineWithOutline(a, b, 2, 2, alwaysVisible); } } break; } return(distance); }