private void DrawBezierPathSceneEditor() { var displayControlPoints = Getdata.displayControlPoints && (GetBezierPath.ControlPointMode != BezierPath.ControlMode.Automatic || !globalDisplaySettings.hideAutoControls); var bounds = GetBezierPath.CalculateBoundsWithTransform(creator.transform); if (Event.current.type == EventType.Repaint) { for (int i = 0; i < GetBezierPath.NumSegments; i++) { var points = GetBezierPath.GetPointsInSegment(i); for (int j = 0; j < points.Length; j++) { points[j] = MathUtility.TransformPoint(points[j], creator.transform, GetBezierPath.Space); } if (Getdata.showPerSegmentBounds) { var segmentBounds = CubicBezierUtility.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 = (GetBezierPath.ControlPointMode == BezierPath.ControlMode.Automatic) ? globalDisplaySettings.handleDisabled : globalDisplaySettings.controlLine; Handles.DrawLine(points[1], points[0]); Handles.DrawLine(points[2], points[3]); } // Draw path var highlightSegment = (i == selectedSegmentIndex && Event.current.shift && draggingHandleIndex == -1 && mouseOverHandleIndex == -1); var segmentColor = (highlightSegment) ? globalDisplaySettings.highlightedPath : globalDisplaySettings.bezierPath; Handles.DrawBezier(points[0], points[3], points[1], points[2], segmentColor, null, 2); } if (Getdata.showPathBounds) { Handles.color = globalDisplaySettings.bounds; Handles.DrawWireCube(bounds.center, bounds.size); } // Draw normals if (Getdata.showNormals) { if (!hasUpdatedNormalsVertexPath) { normalsVertexPath = new VertexPath(GetBezierPath, creator.transform, normalsSpacing); hasUpdatedNormalsVertexPath = true; } if (editingNormalsOld != Getdata.showNormals) { editingNormalsOld = Getdata.showNormals; Repaint(); } var 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 (Getdata.displayAnchorPoints) { for (int i = 0; i < GetBezierPath.NumPoints; i += 3) { DrawHandle(i); } } if (displayControlPoints) { for (int i = 1; i < GetBezierPath.NumPoints - 1; i += 3) { DrawHandle(i); DrawHandle(i + 1); } } }
private void DrawBezierPathInspector() { using (var check = new EditorGUI.ChangeCheckScope()) { // Path options: Getdata.showPathOptions = EditorGUILayout.Foldout(Getdata.showPathOptions, new GUIContent("Bézier Path Options"), true, boldFoldoutStyle); if (Getdata.showPathOptions) { GetBezierPath.Space = (PathSpace)EditorGUILayout.Popup("Space", (int)GetBezierPath.Space, spaceNames); GetBezierPath.ControlPointMode = (BezierPath.ControlMode)EditorGUILayout.EnumPopup(new GUIContent("Control Mode"), GetBezierPath.ControlPointMode); if (GetBezierPath.ControlPointMode == BezierPath.ControlMode.Automatic) { GetBezierPath.AutoControlLength = EditorGUILayout.Slider(new GUIContent("Control Spacing"), GetBezierPath.AutoControlLength, 0, 1); } GetBezierPath.IsClosed = EditorGUILayout.Toggle("Closed Path", GetBezierPath.IsClosed); Getdata.showTransformTool = EditorGUILayout.Toggle(new GUIContent("Enable Transforms"), Getdata.showTransformTool); Tools.hidden = !Getdata.showTransformTool; // Check if out of bounds (can occur after undo operations) if (handleIndexToDisplayAsTransform >= GetBezierPath.NumPoints) { handleIndexToDisplayAsTransform = -1; } // If a point has been selected if (handleIndexToDisplayAsTransform != -1) { EditorGUILayout.LabelField("Selected Point:"); using (new EditorGUI.IndentLevelScope()) { var currentPosition = creator.BezierPath[handleIndexToDisplayAsTransform]; var newPosition = EditorGUILayout.Vector3Field("Position", currentPosition); if (newPosition != currentPosition) { Undo.RecordObject(creator, "Move point"); creator.BezierPath.MovePoint(handleIndexToDisplayAsTransform, newPosition); } // Don't draw the angle field if we aren't selecting an anchor point/not in 3d space if (handleIndexToDisplayAsTransform % 3 == 0 && creator.BezierPath.Space == PathSpace.xyz) { var anchorIndex = handleIndexToDisplayAsTransform / 3; var currentAngle = creator.BezierPath.GetAnchorNormalAngle(anchorIndex); var newAngle = EditorGUILayout.FloatField("Angle", currentAngle); if (newAngle != currentAngle) { Undo.RecordObject(creator, "Set Angle"); creator.BezierPath.SetAnchorNormalAngle(anchorIndex, newAngle); } } } } if (Getdata.showTransformTool & (handleIndexToDisplayAsTransform == -1)) { if (GUILayout.Button("Centre Transform")) { var worldCentre = GetBezierPath.CalculateBoundsWithTransform(creator.transform).center; var transformPos = creator.transform.position; if (GetBezierPath.Space == PathSpace.xy) { transformPos = new Vector3(transformPos.x, transformPos.y, 0); } else if (GetBezierPath.Space == PathSpace.xz) { transformPos = new Vector3(transformPos.x, 0, transformPos.z); } var worldCentreToTransform = transformPos - worldCentre; if (worldCentre != creator.transform.position) { if (worldCentreToTransform != Vector3.zero) { var localCentreToTransform = MathUtility.InverseTransformVector(worldCentreToTransform, creator.transform, GetBezierPath.Space); for (int i = 0; i < GetBezierPath.NumPoints; i++) { GetBezierPath.SetPoint(i, GetBezierPath.GetPoint(i) + localCentreToTransform, true); } } creator.transform.position = worldCentre; GetBezierPath.NotifyPathModified(); } } } if (GUILayout.Button("Reset Path")) { Undo.RecordObject(creator, "Reset Path"); var in2DEditorMode = EditorSettings.defaultBehaviorMode == EditorBehaviorMode.Mode2D; Getdata.ResetBezierPath(creator.transform.position, in2DEditorMode); EditorApplication.QueuePlayerLoopUpdate(); } GUILayout.Space(inspectorSectionSpacing); } Getdata.showNormals = EditorGUILayout.Foldout(Getdata.showNormals, new GUIContent("Normals Options"), true, boldFoldoutStyle); if (Getdata.showNormals) { GetBezierPath.FlipNormals = EditorGUILayout.Toggle(new GUIContent("Flip Normals"), GetBezierPath.FlipNormals); if (GetBezierPath.Space == PathSpace.xyz) { GetBezierPath.GlobalNormalsAngle = EditorGUILayout.Slider(new GUIContent("Global Angle"), GetBezierPath.GlobalNormalsAngle, 0, 360); if (GUILayout.Button("Reset Normals")) { Undo.RecordObject(creator, "Reset Normals"); GetBezierPath.FlipNormals = false; GetBezierPath.ResetNormalAngles(); } } GUILayout.Space(inspectorSectionSpacing); } // Editor display options Getdata.showDisplayOptions = EditorGUILayout.Foldout(Getdata.showDisplayOptions, new GUIContent("Display Options"), true, boldFoldoutStyle); if (Getdata.showDisplayOptions) { Getdata.showPathBounds = GUILayout.Toggle(Getdata.showPathBounds, new GUIContent("Show Path Bounds")); Getdata.showPerSegmentBounds = GUILayout.Toggle(Getdata.showPerSegmentBounds, new GUIContent("Show Segment Bounds")); Getdata.displayAnchorPoints = GUILayout.Toggle(Getdata.displayAnchorPoints, new GUIContent("Show Anchor Points")); if (!(GetBezierPath.ControlPointMode == BezierPath.ControlMode.Automatic && globalDisplaySettings.hideAutoControls)) { Getdata.displayControlPoints = GUILayout.Toggle(Getdata.displayControlPoints, new GUIContent("Show Control Points")); } Getdata.keepConstantHandleSize = GUILayout.Toggle(Getdata.keepConstantHandleSize, new GUIContent("Constant Point Size", constantSizeTooltip)); Getdata.bezierHandleScale = Mathf.Max(0, EditorGUILayout.FloatField(new GUIContent("Handle Scale"), Getdata.bezierHandleScale)); DrawGlobalDisplaySettingsInspector(); } if (check.changed) { SceneView.RepaintAll(); EditorApplication.QueuePlayerLoopUpdate(); } } }