void AddItem() { LevelSplinePoint newItem = new LevelSplinePoint(); newItem.points = new List <Vector3>(); int prevI = splinePoints.pointsList.Count - 1; int prevPrevI = splinePoints.pointsList.Count - 2; if (prevI >= 0) { if (splinePoints.pointsList[prevI].points.Count > 0) { newItem.points.Add(splinePoints.pointsList[prevI].points[0]); } if ((prevPrevI > 0) && (splinePoints.pointsList[prevPrevI].points.Count > 0)) { Vector3 dir = splinePoints.pointsList[prevI].points[0] - splinePoints.pointsList[prevPrevI].points[0]; newItem.points[0] += splinePoints.distance * dir.normalized; } } else { newItem.points.Add(Vector3.zero); } /* * if (splinePoints.pointsList.Count >= 2) * { * Vector3 dir = * } */ splinePoints.pointsList.Add(newItem); viewIndex = splinePoints.pointsList.Count - 1; }
private void OnSceneGUI(SceneView sceneView) { if (splinePoints.pointsList.Count <= 0) { return; } //if (splinePoints.activeIndex < 0) // return; //Transform handleTransform = new Transform(); //Quaternion handleRotation = Tools.pivotRotation == PivotRotation.Local ? handleTransform.rotation : Quaternion.identity; Handles.color = Color.blue; LevelSplinePoint currPoint = null; LevelSplinePoint prevPoint = null; for (int i = 0; i < splinePoints.pointsList.Count; i++) { currPoint = splinePoints.pointsList[i]; if (i > 0) { prevPoint = splinePoints.pointsList[i - 1]; } if (currPoint != null) { for (int j = 0; j < currPoint.points.Count; j++) { Vector3 position = currPoint.points[j]; Quaternion rotation = Quaternion.identity; // Connect points with line if (prevPoint != null) { Vector3 prevPosition; // Get available point from prev SlinePoint if (j < prevPoint.points.Count) { prevPosition = prevPoint.points[j]; } else { if (prevPoint.points.Count > 0) { prevPosition = prevPoint.points[prevPoint.points.Count - 1]; } else { continue; } } Handles.DrawLine(position, prevPosition); // If we draw last point - connect all other points from prev point if (j == currPoint.points.Count - 1) { for (int k = currPoint.points.Count; k < prevPoint.points.Count; k++) { Handles.DrawLine(position, prevPoint.points[k]); } } } Handles.SphereCap(j, position, rotation, 0.5f); if (i == viewIndex) { EditorGUI.BeginChangeCheck(); position = Handles.DoPositionHandle(position, rotation); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(splinePoints, "Move Point"); EditorUtility.SetDirty(splinePoints); currPoint.points[j] = position; } //ChangePointCoordinates(handleTransform.InverseTransformPoint(position)); /*EditorGUI.BeginChangeCheck(); * rotation = Handles.RotationHandle(rotation, pointInWorldSpace); * if (EditorGUI.EndChangeCheck()) * ChangePointRotation(rotation);*/ } } } } }