public override void OnInspectorGUI() { base.OnInspectorGUI(); spline = (SplineComputer)target; Undo.RecordObject(spline, "Edit Points"); if (splines.Length == 1) { SplineEditorGUI.BeginContainerBox(ref pathEditor.open, "Edit"); if (pathEditor.open) { SplineEditor.Space lastSpace = pathEditor.space; pathEditor.DrawInspector(); if (lastSpace != pathEditor.space) { SplinePrefs.pointEditSpace = (SplineComputer.Space)pathEditor.space; SplinePrefs.SavePrefs(); } } else if (pathEditor.lastEditorTool != Tool.None && Tools.current == Tool.None) { Tools.current = pathEditor.lastEditorTool; } SplineEditorGUI.EndContainerBox(); } SplineEditorGUI.BeginContainerBox(ref computerEditor.open, "Spline Computer"); if (computerEditor.open) { computerEditor.DrawInspector(); } SplineEditorGUI.EndContainerBox(); if (splines.Length == 1) { SplineEditorGUI.BeginContainerBox(ref triggersEditor.open, "Triggers"); if (triggersEditor.open) { triggersEditor.DrawInspector(); } SplineEditorGUI.EndContainerBox(); SplineEditorGUI.BeginContainerBox(ref debugEditor.open, "Editor Properties"); if (debugEditor.open) { debugEditor.DrawInspector(); } SplineEditorGUI.EndContainerBox(); } if (GUI.changed) { if (spline.isClosed) { pathEditor.points[pathEditor.points.Length - 1] = pathEditor.points[0]; } EditorUtility.SetDirty(spline); } }
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; } } }