public override void OnInspectorGUI() { base.OnInspectorGUI(); spline = target as SplinePath; if (selectedIndex >= 0 && selectedIndex < spline.ControlPointCount) { DrawSelectedPointInspector(); Tools.hidden = true; } else { Tools.hidden = false; } if (GUILayout.Button("Add Curve")) { Undo.RecordObject(spline, "Add Curve"); spline.AddCurve(); EditorUtility.SetDirty(spline); } if (spline.CurveCount > 1 && GUILayout.Button("Remove Curve")) { Undo.RecordObject(spline, "Remove Curve"); spline.RemoveCurve(); EditorUtility.SetDirty(spline); } if (GUI.changed) { spline.OnPathChanged(spline); } }
protected virtual void OnSceneGUI() { spline = target as SplinePath; handleTransform = spline.transform; if (currentTool != Tools.current || currentPivotRotation != Tools.pivotRotation) { ResetHandleSettings(); currentTool = Tools.current; currentPivotRotation = Tools.pivotRotation; } Vector3 p0 = ShowPoint(0); for (int i = 1; i < spline.ControlPointCount; i += 3) { Vector3 p1 = ShowPoint(i); Vector3 p2 = ShowPoint(i + 1); Vector3 p3 = ShowPoint(i + 2); Handles.color = Color.gray; Handles.DrawLine(p0, p1); Handles.DrawLine(p2, p3); Handles.DrawBezier(p0, p3, p1, p2, Color.white, null, 2f); p0 = p3; } ShowDirections(); }
private void OnEnable() { Undo.undoRedoPerformed += UndoRedoPerformed; spline = target as SplinePath; if (!Application.IsPlaying(spline)) { spline.OnPathChanged(spline); } }
private void UndoRedoPerformed() { spline = target as SplinePath; if (spline != null) { spline.OnPathChanged(spline); } else { Undo.undoRedoPerformed -= UndoRedoPerformed; } }
protected virtual void OnSceneGUI() { spline = target as SplinePath; handleTransform = spline.transform; if (currentTool != Tools.current || currentPivotRotation != Tools.pivotRotation) { currentTool = Tools.current; currentPivotRotation = Tools.pivotRotation; ResetHandleSettings(); } Vector3 p0 = ShowPoint(0); for (int i = 1; i < spline.ControlPointCount; i += 3) { Vector3 p1 = ShowPoint(i); Vector3 p2 = ShowPoint(i + 1); Vector3 p3 = ShowPoint(i + 2); Handles.color = Color.gray; Handles.DrawLine(p0, p1); Handles.DrawLine(p2, p3); Handles.DrawBezier(p0, p3, p1, p2, Color.white, null, 2f); p0 = p3; } Handles.color = Color.green.SetA(0.3f); Handles.SphereHandleCap(0, spline.GetPoint(0f), Quaternion.identity, 0.1f, EventType.Repaint); Handles.color = Color.red.SetA(0.3f); Handles.SphereHandleCap(0, spline.GetPoint(1f), Quaternion.identity, 0.1f, EventType.Repaint); if (spline.NormalType == NormalType.Perpendicular) { for (int i = 0; i < spline.Normals.Length; i++) { if (i % 3 == 0) { Vector3 pos = spline.GetControlPoint(i); Vector3 normal = spline.GetControlNormal(i); Handles.color = Color.red; Handles.DrawLine(pos, pos + normal * 0.8f); } } } int numIterations = 10 * spline.ControlPointCount; for (int i = 1; i < numIterations; i++) { float alpha = i / (float)numIterations; Vector3 pos = spline.GetPoint(alpha); Vector3 normal = spline.GetNormal(alpha); Handles.color = Color.green; Handles.DrawLine(pos, pos + normal * 0.4f); } }