void DrawBezierPathInspector() { using (var check = new EditorGUI.ChangeCheckScope()) { EditorGUILayout.HelpBox("Path calculation functions.", MessageType.Info); // Path distance to position data.pathDist = EditorGUILayout.FloatField("Path Distance", data.pathDist); if (GUILayout.Button("Get World Coordinates")) { Vector3 pos = creator.path.GetPointAtDistance(data.pathDist); Vector3 rots = creator.path.GetRotationAtDistance(data.pathDist).eulerAngles; Debug.Log($"World - Pos X: {pos.x:.000}, Pos Y: {pos.y:.000}, Pos Z: {pos.z:.000}, Rot X: {rots.x:.000}, Rot Y: {rots.y:.000}, Rot Z: {rots.z:.000}"); } data.pathWorld = EditorGUILayout.Vector3Field("World Position", data.pathWorld); if (GUILayout.Button("Get Path Position")) { float pos = creator.path.GetClosestDistanceAlongPath(data.pathWorld); Vector3 rots = creator.path.GetRotationAtDistance(pos).eulerAngles; Debug.Log($"Path - Path Distance: {pos:.000}, Rot X: {rots.x:.000}, Rot Y: {rots.y:.000}, Rot Z: {rots.z:.000}"); } // Path options: data.showPathOptions = EditorGUILayout.Foldout(data.showPathOptions, new GUIContent("Bézier Path Options"), true, boldFoldoutStyle); if (data.showPathOptions) { bezierPath.Space = (PathSpace)EditorGUILayout.Popup("Space", (int)bezierPath.Space, spaceNames); bezierPath.ControlPointMode = (BezierPath.ControlMode)EditorGUILayout.EnumPopup(new GUIContent("Control Mode"), bezierPath.ControlPointMode); if (bezierPath.ControlPointMode == BezierPath.ControlMode.Automatic) { bezierPath.AutoControlLength = EditorGUILayout.Slider(new GUIContent("Control Spacing"), bezierPath.AutoControlLength, 0, 1); } bezierPath.IsClosed = EditorGUILayout.Toggle("Closed Path", bezierPath.IsClosed); data.pathTransformationEnabled = EditorGUILayout.Toggle(new GUIContent("Enable Transforms"), data.pathTransformationEnabled); // 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 (GUILayout.Button("Reset Path")) { Undo.RecordObject(creator, "Reset Path"); bool in2DEditorMode = EditorSettings.defaultBehaviorMode == EditorBehaviorMode.Mode2D; data.ResetBezierPath(creator.transform.position, in2DEditorMode); EditorApplication.QueuePlayerLoopUpdate(); } if (GUILayout.Button("Import OBJ")) { // Select file. string path = EditorUtility.OpenFilePanel("Select obj file", "", "obj"); // Import. ObjImporter.meshStruct holderMesh = ObjImporter.createMeshStruct(path); ObjImporter.populateMeshStruct(ref holderMesh); //Assign data.bezierPath = new BezierPath(holderMesh.vertices, false, PathSpace.xyz); } GUILayout.Space(inspectorSectionSpacing); } data.showNormals = EditorGUILayout.Foldout(data.showNormals, new GUIContent("Normals Options"), true, boldFoldoutStyle); if (data.showNormals) { bezierPath.FlipNormals = EditorGUILayout.Toggle(new GUIContent("Flip Normals"), bezierPath.FlipNormals); if (bezierPath.Space == PathSpace.xyz) { bezierPath.GlobalNormalsAngle = EditorGUILayout.Slider(new GUIContent("Global Angle"), bezierPath.GlobalNormalsAngle, 0, 360); if (GUILayout.Button("Reset Normals")) { Undo.RecordObject(creator, "Reset Normals"); bezierPath.FlipNormals = false; bezierPath.ResetNormalAngles(); } } GUILayout.Space(inspectorSectionSpacing); } // Editor display options data.showDisplayOptions = EditorGUILayout.Foldout(data.showDisplayOptions, new GUIContent("Display Options"), true, boldFoldoutStyle); if (data.showDisplayOptions) { data.showPathBounds = GUILayout.Toggle(data.showPathBounds, new GUIContent("Show Path Bounds")); data.showPerSegmentBounds = GUILayout.Toggle(data.showPerSegmentBounds, new GUIContent("Show Segment Bounds")); data.displayAnchorPoints = GUILayout.Toggle(data.displayAnchorPoints, new GUIContent("Show Anchor Points")); if (!(bezierPath.ControlPointMode == BezierPath.ControlMode.Automatic && globalDisplaySettings.hideAutoControls)) { data.displayControlPoints = GUILayout.Toggle(data.displayControlPoints, new GUIContent("Show Control Points")); } data.keepConstantHandleSize = GUILayout.Toggle(data.keepConstantHandleSize, new GUIContent("Constant Point Size", constantSizeTooltip)); data.bezierHandleScale = Mathf.Max(0, EditorGUILayout.FloatField(new GUIContent("Handle Scale"), data.bezierHandleScale)); DrawGlobalDisplaySettingsInspector(); } if (check.changed) { SceneView.RepaintAll(); EditorApplication.QueuePlayerLoopUpdate(); } } }