private void OnSceneGUI() { bezierSpline = target as SplineBezierCurve; bezierCurveTransform = bezierSpline.transform; bezierCurveRotation = bezierCurveTransform.rotation; Vector3 p0 = ShowPoint(0); Vector3 rp0 = ShowPointRot(0); for (int i = 1; i < bezierSpline.ControlPointCount; i += 3) { Vector3 p1 = ShowPoint(i); Vector3 p2 = ShowPoint(i + 1); Vector3 p3 = ShowPoint(i + 2); Vector3 rp1 = ShowPointRot((i + 2) / 3); Handles.color = Color.red; Handles.DrawLine(p0, rp0); Handles.DrawLine(p3, rp1); Handles.color = Color.gray; Handles.DrawLine(p0, p1); Handles.DrawLine(p2, p3); Handles.DrawBezier(p0, p3, p1, p2, Color.white, null, 2f); p0 = p3; rp0 = rp1; } if (bezierSpline.DrawVelocity) { ShowDirections(); } }
public override void OnInspectorGUI() { bezierSpline = target as SplineBezierCurve; if (selectedIndex >= 0 && selectedIndex < bezierSpline.ControlPointCount) { DrawSelectedPointInspector(); } else if (selectedIndexRot >= 0 && selectedIndexRot <= bezierSpline.CurveCount) { DrawSelectedRotPointInspector(); } if (GUILayout.Button("Add Curve")) { Undo.RecordObject(bezierSpline, "Add curve to spline"); bezierSpline.AddCurve(); EditorUtility.SetDirty(bezierSpline); } if (GUILayout.Button("Remove Curve")) { Undo.RecordObject(bezierSpline, "Remove curve to spline"); bezierSpline.RemoveCurve(); EditorUtility.SetDirty(bezierSpline); } if (GUILayout.Button("Turn Looping " + ((bezierSpline.IsLoop) ? "Off" : "On"))) { Undo.RecordObject(bezierSpline, "Toggled looping"); bezierSpline.IsLoop = !bezierSpline.IsLoop; if (bezierSpline.IsLoop == false) { bezierSpline.RemoveLoop(); } EditorUtility.SetDirty(bezierSpline); } if (GUILayout.Button("Smooth out tangent points")) { Undo.RecordObject(bezierSpline, "Smoothed out tangents on curve."); bezierSpline.AlignAnchors(); EditorUtility.SetDirty(bezierSpline); } if (GUILayout.Button("Turn Velocity Lines " + ((bezierSpline.DrawVelocity) ? "Off" : "On"))) { Undo.RecordObject(bezierSpline, "Toggled velocity lines"); bezierSpline.DrawVelocity = !bezierSpline.DrawVelocity; EditorUtility.SetDirty(bezierSpline); } if (GUILayout.Button("Turn Gizmos " + ((bezierSpline.DrawGizmos) ? "Off" : "On"))) { Undo.RecordObject(bezierSpline, "Toggled gizmos"); bezierSpline.DrawGizmos = !bezierSpline.DrawGizmos; EditorUtility.SetDirty(bezierSpline); } }