protected void CreatePoints(int count, SplinePoint.Type type) { if (points.Length != count) { points = new SplinePoint[count]; } for (int i = 0; i < points.Length; i++) { points[i].type = type; points[i].normal = Vector3.up; points[i].color = Color.white; points[i].size = 1f; } }
void PointMenu() { if (selectedPoints.Count == 0 || points.Length == 0) { return; } //Otherwise show the editing menu + the point selection menu Vector3 avgPos = Vector3.zero; Vector3 avgTan = Vector3.zero; Vector3 avgTan2 = Vector3.zero; Vector3 avgNormal = Vector3.zero; float avgSize = 0f; Color avgColor = Color.clear; for (int i = 0; i < selectedPoints.Count; i++) { avgPos += points[selectedPoints[i]].position; avgNormal += points[selectedPoints[i]].normal; avgSize += points[selectedPoints[i]].size; avgTan += points[selectedPoints[i]].tangent; avgTan2 += points[selectedPoints[i]].tangent2; avgColor += points[selectedPoints[i]].color; } avgPos /= selectedPoints.Count; avgTan /= selectedPoints.Count; avgTan2 /= selectedPoints.Count; avgSize /= selectedPoints.Count; avgColor /= selectedPoints.Count; avgNormal.Normalize(); SplinePoint avgPoint = new SplinePoint(avgPos, avgPos); avgPoint.tangent = avgTan; avgPoint.tangent2 = avgTan2; avgPoint.size = avgSize; avgPoint.color = avgColor; avgPoint.type = points[selectedPoints[0]].type; SplinePoint.Type lastType = avgPoint.type; avgPoint.normal = avgNormal; EditorGUI.BeginChangeCheck(); SplineComputer.Space lastSpace = SplinePrefs.pointEditSpace; SplinePrefs.pointEditSpace = (SplineComputer.Space)EditorGUILayout.EnumPopup("Edit Space", SplinePrefs.pointEditSpace); if (lastSpace != SplinePrefs.pointEditSpace) { SplinePrefs.SavePrefs(); } if (splineType == Spline.Type.Bezier) { if (is2D) { avgPoint.SetTangentPosition(TransformedPositionField2D("Tangent 1", avgPoint.tangent)); avgPoint.SetTangent2Position(TransformedPositionField2D("Tangent 2", avgPoint.tangent2)); } else { avgPoint.SetTangentPosition(TransformedPositionField("Tangent 1", avgPoint.tangent)); avgPoint.SetTangent2Position(TransformedPositionField("Tangent 2", avgPoint.tangent2)); } } if (is2D) { avgPoint.SetPosition(TransformedPositionField2D("Position", avgPoint.position)); } else { avgPoint.SetPosition(TransformedPositionField("Position", avgPoint.position)); } if (!is2D) { if (SplinePrefs.pointEditSpace == SplineComputer.Space.Local) { avgPoint.normal = _matrix.inverse.MultiplyVector(avgPoint.normal); } avgPoint.normal = TransformedPositionField("Normal", avgPoint.normal); if (SplinePrefs.pointEditSpace == SplineComputer.Space.Local) { avgPoint.normal = _matrix.MultiplyVector(avgPoint.normal); } } avgPoint.size = EditorGUILayout.FloatField("Size", avgPoint.size); avgPoint.color = EditorGUILayout.ColorField("Color", avgPoint.color); if (splineType == Spline.Type.Bezier) { avgPoint.type = (SplinePoint.Type)EditorGUILayout.EnumPopup("Point Type", avgPoint.type); } if (!EditorGUI.EndChangeCheck()) { return; } RecordUndo("Edit Points"); for (int i = 0; i < selectedPoints.Count; i++) { points[selectedPoints[i]].SetPosition(GetChangedVector(avgPos, avgPoint.position, points[selectedPoints[i]].position)); points[selectedPoints[i]].normal = GetChangedVector(avgNormal, avgPoint.normal, points[selectedPoints[i]].normal); if (splineType == Spline.Type.Bezier) { points[selectedPoints[i]].SetTangentPosition(GetChangedVector(avgTan, avgPoint.tangent, points[selectedPoints[i]].tangent)); points[selectedPoints[i]].SetTangent2Position(GetChangedVector(avgTan2, avgPoint.tangent2, points[selectedPoints[i]].tangent2)); } if (avgPoint.size != avgSize) { points[selectedPoints[i]].size = avgPoint.size; } if (avgColor != avgPoint.color) { points[selectedPoints[i]].color = avgPoint.color; } if (lastType != avgPoint.type) { points[selectedPoints[i]].type = avgPoint.type; } } }