public static Vector3 Edge2DHandleOffset(int id, Vector3 from, Vector3 to, Vector3 position, Vector3 handleDir, Vector3 slideDir1, Vector3 slideDir2, float handleSize, CapFunction capFunction, Axes axes = Axes.None, Vector3?snappingSteps = null) { var evt = Event.current; switch (evt.GetTypeForControl(id)) { case EventType.Layout: { if (Tools.current == Tool.View || Tools.current == Tool.None || evt.alt) { break; } UnityEditor.HandleUtility.AddControl(id, UnityEditor.HandleUtility.DistanceToLine(from, to) * 0.5f); break; } case EventType.Repaint: { var sceneView = SceneView.currentDrawingSceneView; if (sceneView && Tools.current != Tool.View && Tools.current != Tool.None && !evt.alt) { if (UnityEditor.HandleUtility.nearestControl == id || EditorGUIUtility.hotControl == id) { var rect = sceneView.position; rect.min = Vector2.zero; EditorGUIUtility.AddCursorRect(rect, SceneHandleUtility.GetCursorForEdge(from, to)); } } if (EditorGUIUtility.keyboardControl == id) { SceneHandles.DrawAAPolyLine(3.0f, from, to); } else { SceneHandles.DrawAAPolyLine(2.5f, from, to); } break; } } var points = new Vector3[] { from, to }; var result = Slider2D.Do(id, points, position, Vector3.zero, handleDir, slideDir1, slideDir2, handleSize, capFunction, axes, snappingSteps: snappingSteps); return(result[0] - from); }
public static void DrawEdgeHandle(int id, Vector3 from, Vector3 to, bool setCursor, bool renderEdge = true, bool setControl = true, MouseCursor?cursor = null) { var evt = Event.current; switch (evt.GetTypeForControl(id)) { case EventType.Layout: { if (setCursor && setControl) { if (InCameraOrbitMode) { break; } UnityEditor.HandleUtility.AddControl(id, UnityEditor.HandleUtility.DistanceToLine(from, to) * 0.5f); } break; } case EventType.Repaint: { if (setCursor && !InCameraOrbitMode) { if (!cursor.HasValue) { SetCursor(id, from, to); } else { SetCursor(id, cursor.Value); } } if (renderEdge) { linePoints[0] = from; linePoints[1] = to; if (EditorGUIUtility.keyboardControl == id) { SceneHandles.DrawAAPolyLine(3.5f, linePoints); } else { SceneHandles.DrawAAPolyLine(2.5f, linePoints); } } break; } } }
public static Vector3 Edge1DHandleOffset(int id, Axis axis, Vector3 from, Vector3 to, Vector3 position, Vector3 direction, float snappingStep, float handleSize, CapFunction capFunction) { var evt = Event.current; switch (evt.GetTypeForControl(id)) { case EventType.Layout: { if (Tools.current == Tool.View || Tools.current == Tool.None || evt.alt) { break; } UnityEditor.HandleUtility.AddControl(id, UnityEditor.HandleUtility.DistanceToLine(from, to)); break; } case EventType.Repaint: { var sceneView = SceneView.currentDrawingSceneView; if (sceneView && Tools.current != Tool.View && Tools.current != Tool.None && !evt.alt) { var rect = sceneView.position; rect.min = Vector2.zero; var hovering = UnityEditor.HandleUtility.nearestControl == id && UnityEditor.HandleUtility.DistanceToLine(from, to) < 10; // in case multiple edges share the same id, we want to ignore those that aren't even close if (EditorGUIUtility.hotControl == id || hovering) { EditorGUIUtility.AddCursorRect(rect, SceneHandleUtility.GetCursorForEdge(from, to)); } } SceneHandles.DrawAAPolyLine(3.0f, from, to); break; } } var points = new Vector3[] { from, to }; var result = Slider1DHandle(id, axis, points, position, direction, snappingStep, handleSize, capFunction); return(result[0] - from); }
public static Vector3 Edge1DHandleOffset(int id, Axis axis, Vector3 from, Vector3 to, Vector3 position, Vector3 direction, float snappingStep, float handleSize, CapFunction capFunction) { if (snappingStep == 0) { snappingStep = Snapping.MoveSnappingSteps[(int)axis]; } if (handleSize == 0) { handleSize = UnityEditor.HandleUtility.GetHandleSize(position) * 0.05f; } var evt = Event.current; switch (evt.GetTypeForControl(id)) { case EventType.Layout: { if (SceneHandles.InCameraOrbitMode) { break; } UnityEditor.HandleUtility.AddControl(id, UnityEditor.HandleUtility.DistanceToLine(from, to)); break; } case EventType.Repaint: { SetCursor(id, from, to); linePoints[0] = from; linePoints[1] = to; SceneHandles.DrawAAPolyLine(3.0f, linePoints); break; } } var points = new Vector3[] { from, to }; var result = Slider1DHandle(id, axis, points, position, direction, snappingStep, handleSize, capFunction); return(result[0] - from); }
public static void DrawAngle(UnityEngine.Vector3 center, UnityEngine.Vector3 direction, UnityEngine.Vector3 axis, float angle) { var rotation = UnityEngine.Quaternion.AngleAxis(angle, axis); var centerSize = UnityEditor.HandleUtility.GetHandleSize(center); var maxSize = direction.magnitude; var xdir = direction / maxSize; //var ydir = UnityEngine.Vector3.Cross(xdir, axis); var handleSize = Mathf.Min(centerSize, maxSize); var drawAngle = UnityEngine.Mathf.Clamp(angle, -360, 360); var realLength = Mathf.Max(1, Mathf.CeilToInt((anglePoints.Length / 360.0f) * Mathf.Abs(drawAngle))); var pointSize = centerSize * 0.04f; SceneHandles.color = SceneHandles.StateColor(SceneHandles.measureColor); SceneHandles.DrawAAPolyLine(center + (xdir * pointSize), center + direction); SceneHandles.DrawAAPolyLine(center + (rotation * (xdir * pointSize)), center + (rotation * direction)); SceneHandles.DrawWireDisc(center, Vector3.forward, pointSize); direction = xdir * handleSize; if (UnityEngine.Mathf.Abs(angle) > 0.0f) { var angleStep = drawAngle / realLength; var curAngle = 0.0f; for (int i = 0; i < realLength; i++) { anglePoints[i] = center + (UnityEngine.Quaternion.AngleAxis(curAngle, axis) * direction); curAngle += angleStep; } SceneHandles.DrawDottedLines(anglePoints.Take(realLength).ToArray(), 4.0f); rotation = UnityEngine.Quaternion.AngleAxis(angle, axis); var right = rotation * Vector3.right; var endPoint = center + (rotation * direction); var arrowSize = handleSize * 0.2f; // UnityEditor.HandleUtility.GetHandleSize(endPoint) * 0.2f; if (angle < 0.0f) { DrawFlatArrow(endPoint, -right, arrowSize); } else { DrawFlatArrow(endPoint, right, arrowSize); } } Vector3 facing; Vector3 position; if (handleSize == maxSize) { facing = rotation * xdir; position = center + (facing * handleSize); } else { var halfRotation = UnityEngine.Quaternion.AngleAxis(drawAngle / 2.0f, axis); facing = halfRotation * xdir; position = center; } DrawLabel(position, facing, 5, angle + "°"); }