public static MouseCursor RotatedResizeCursor(Vector2 direction) { var cameraDirection = GetCameraDirection(direction); var angle = Helpers2D.GetAngle(cameraDirection); MouseCursor cursor; if (Mathf.Abs(Mathf.DeltaAngle(angle, 0)) <= 22.5f || Mathf.Abs(Mathf.DeltaAngle(angle, 180)) <= 22.5f) { cursor = MouseCursor.ResizeHorizontal; } else if (Mathf.Abs(Mathf.DeltaAngle(angle, 45)) <= 22.5f || Mathf.Abs(Mathf.DeltaAngle(angle, 225)) <= 22.5f) { cursor = MouseCursor.ResizeUpRight; } else if (Mathf.Abs(Mathf.DeltaAngle(angle, 135)) <= 22.5f || Mathf.Abs(Mathf.DeltaAngle(angle, 315)) <= 22.5f) { cursor = MouseCursor.ResizeUpLeft; } else { cursor = MouseCursor.ResizeVertical; } return(cursor); }
public static float AngleSlider(int controlID, HandleDrawerBase drawer, Vector2 center, float angle, float distanceFromCenter, float handleSize, float snap = 0) { var info = StateObject.Get <AngleSliderInfo>(controlID); var current = Event.current; if (GUIUtility.hotControl == controlID) { angle = info.angle; } var handlePosition = center + Helpers2D.GetDirection(angle) * distanceFromCenter; if (Event.current.type == EventType.layout) { var distanceFromDrawer = drawer.GetDistance(handlePosition, handleSize, angle); HandleUtility.AddControl(controlID, distanceFromDrawer); } var typeForControl = current.GetTypeForControl(controlID); switch (typeForControl) { case EventType.mouseMove: var hovering = HandleUtility.nearestControl == controlID && (GUIUtility.hotControl == 0 || GUIUtility.hotControl == controlID); if (info.hovering != hovering) { current.Use(); info.hovering = hovering; } break; } if (GUIUtility.hotControl == controlID) { //active! switch (typeForControl) { case EventType.mouseUp: if (current.button == info.button) { current.Use(); GUIUtility.hotControl = 0; } break; case EventType.mouseDrag: current.Use(); info.mousePosition += new Vector2(current.delta.x, current.delta.y); Vector2 worldMousePosition = HandlePointToWorld(info.mousePosition); var mouseAngle = Helpers2D.GetAngle(worldMousePosition - center); info.angle += Mathf.DeltaAngle(info.mouseAngle, mouseAngle); info.mouseAngle = mouseAngle; angle = Handles.SnapValue(info.angle, snap); GUI.changed = true; break; } } else { if (GUIUtility.hotControl == 0) { switch (typeForControl) { case EventType.mouseDown: if (HandleUtility.nearestControl == controlID && current.button == 0) { info.button = current.button; info.mousePosition = current.mousePosition; Vector2 worldMousePosition = HandlePointToWorld(info.mousePosition); var mouseAngle = Helpers2D.GetAngle(worldMousePosition - center); info.mouseAngle = mouseAngle; info.angle = angle; current.Use(); GUIUtility.hotControl = controlID; } break; } } } if (typeForControl == EventType.repaint) { if (GUIUtility.hotControl == controlID || (GUIUtility.hotControl == 0 && info.hovering)) { SetEditorCursor(MouseCursor.RotateArrow, controlID); } drawer.Draw(controlID, handlePosition, handleSize, angle, info.hovering); } return(angle); }