// Draw the path when path objected is not selected (if enabled in settings) void OnDrawGizmos() { // Only draw path gizmo if the path object is not selected // (editor script is resposible for drawing when selected) GameObject selectedObj = UnityEditor.Selection.activeGameObject; if (selectedObj == gameObject || VertexPath == null) { return; } VertexPath.UpdateTransform(transform); if (!GlobalEditorDisplaySettings.visibleWhenNotSelected) { return; } Gizmos.color = GlobalEditorDisplaySettings.BezierPath; for (int i = 0; i < VertexPath.NumPoints; i++) { int nextI = i + 1; if (nextI >= VertexPath.NumPoints) { if (!VertexPath.isClosedLoop) { break; } nextI %= VertexPath.NumPoints; } Gizmos.DrawLine(VertexPath.GetPoint(i), VertexPath.GetPoint(nextI)); } }
void DrawBezierPathSceneEditor() { bool displayControlPoints = Data.displayControlPoints && (BezierPath.ControlPointMode != BezierPath.ControlMode.Automatic || !GlobalDisplaySettings.hideAutoControls); Bounds bounds = BezierPath.CalculateBoundsWithTransform(creator.transform); if (Event.current.type == EventType.Repaint) { for (int i = 0; i < BezierPath.NumSegments; i++) { Vector3[] points = BezierPath.GetPointsInSegment(i); for (int j = 0; j < points.Length; j++) { points[j] = MathUtility.TransformPoint(points[j], creator.transform, BezierPath.Space); } if (Data.showPerSegmentBounds) { Bounds segmentBounds = PathUtility.CalculateSegmentBounds(points[0], points[1], points[2], points[3]); Handles.color = GlobalDisplaySettings.segmentBounds; Handles.DrawWireCube(segmentBounds.center, segmentBounds.size); } // Draw lines between control points if (displayControlPoints) { Handles.color = (BezierPath.ControlPointMode == BezierPath.ControlMode.Automatic) ? GlobalDisplaySettings.handleDisabled : GlobalDisplaySettings.controlLine; Handles.DrawLine(points[1], points[0]); Handles.DrawLine(points[2], points[3]); } // Draw VertexPath bool highlightSegment = (i == selectedSegmentIndex && Event.current.shift && draggingHandleIndex == -1 && mouseOverHandleIndex == -1); Color segmentCol = (highlightSegment) ? GlobalDisplaySettings.highlightedPath : GlobalDisplaySettings.BezierPath; Handles.DrawBezier(points[0], points[3], points[1], points[2], segmentCol, null, 2); } if (Data.showPathBounds) { Handles.color = GlobalDisplaySettings.bounds; Handles.DrawWireCube(bounds.center, bounds.size); } // Draw normals if (Data.showNormals) { if (!hasUpdatedNormalsVertexPath) { normalsVertexPath = new VertexPath(BezierPath, creator.transform, normalsSpacing); hasUpdatedNormalsVertexPath = true; } if (editingNormalsOld != Data.showNormals) { editingNormalsOld = Data.showNormals; Repaint(); } Vector3[] normalLines = new Vector3[normalsVertexPath.NumPoints * 2]; Handles.color = GlobalDisplaySettings.normals; for (int i = 0; i < normalsVertexPath.NumPoints; i++) { normalLines[i * 2] = normalsVertexPath.GetPoint(i); normalLines[i * 2 + 1] = normalsVertexPath.GetPoint(i) + normalsVertexPath.GetNormal(i) * GlobalDisplaySettings.normalsLength; } Handles.DrawLines(normalLines); } } if (Data.displayAnchorPoints) { for (int i = 0; i < BezierPath.NumPoints; i += 3) { DrawHandle(i); } } if (displayControlPoints) { for (int i = 1; i < BezierPath.NumPoints - 1; i += 3) { DrawHandle(i); DrawHandle(i + 1); } } }