private void HandleSegmentModifications()
        {
            Handles.zTest = UnityEngine.Rendering.CompareFunction.Less;
            List <GSplineSegment> segments = instance.Spline.Segments;
            List <GSplineAnchor>  anchors  = instance.Spline.Anchors;

            for (int i = 0; i < segments.Count; ++i)
            {
                if (!instance.Spline.IsSegmentValid(i))
                {
                    continue;
                }
                if (i == selectedSegmentIndex)
                {
                    HandleSelectedSegmentModifications();
                }
                int           i0            = segments[i].StartIndex;
                int           i1            = segments[i].EndIndex;
                GSplineAnchor a0            = anchors[i0];
                GSplineAnchor a1            = anchors[i1];
                Vector3       startPosition = a0.Position;
                Vector3       endPosition   = a1.Position;
                Vector3       startTangent  = startPosition + segments[i].StartTangent;
                Vector3       endTangent    = endPosition + segments[i].EndTangent;
                Color         color         = i == selectedSegmentIndex ?
                                              GGriffinSettings.Instance.SplineToolSettings.SelectedElementColor :
                                              GGriffinSettings.Instance.SplineToolSettings.SegmentColor;
                Handles.color = color;
                Vector3[] bezierPoints = Handles.MakeBezierPoints(startPosition, endPosition, startTangent, endTangent, instance.Smoothness);
                Handles.DrawAAPolyLine(BEZIER_WIDTH, bezierPoints);

                if (GGuiEventUtilities.IsLeftMouseUp)
                {
                    float d0 = GHandleUtility.DistanceMouseToSpline(Event.current.mousePosition, bezierPoints);
                    float d1 = GHandleUtility.DistanceMouseToPoint(Event.current.mousePosition, bezierPoints[0] - instance.PositionOffset);
                    float d2 = GHandleUtility.DistanceMouseToPoint(Event.current.mousePosition, bezierPoints[bezierPoints.Length - 1] - instance.PositionOffset);
                    if (d0 <= BEZIER_SELECT_DISTANCE &&
                        d1 > BEZIER_SELECT_DISTANCE &&
                        d2 > BEZIER_SELECT_DISTANCE)
                    {
                        selectedSegmentIndex = i;
                        if (GGuiEventUtilities.IsCtrl)
                        {
                            instance.Spline.Segments.RemoveAt(selectedSegmentIndex);
                            selectedSegmentIndex = -1;
                            GUI.changed          = true;
                        }
                        //don't Use() the event here
                    }
                }
            }
            Handles.zTest = UnityEngine.Rendering.CompareFunction.Always;
        }
        private void HandleAnchorModifications()
        {
            List <GSplineAnchor> anchors = instance.Spline.Anchors;

            for (int i = 0; i < anchors.Count; ++i)
            {
                Handles.zTest = UnityEngine.Rendering.CompareFunction.Less;
                Handles.color = i == selectedAnchorIndex ?
                                GGriffinSettings.Instance.SplineToolSettings.SelectedElementColor :
                                GGriffinSettings.Instance.SplineToolSettings.AnchorColor;
                GSplineAnchor a = anchors[i];
                if (a == null)
                {
                    continue;
                }
                Vector3 groundPosition = new Vector3(a.Position.x, 0, a.Position.z);
                Handles.DrawDottedLine(
                    groundPosition,
                    a.Position, 5);
                if (GGuiEventUtilities.IsLeftMouseUp && GGuiEventUtilities.IsCtrl)
                {
                    float d0 = GHandleUtility.DistanceMouseToLine(Event.current.mousePosition, groundPosition, a.Position);
                    float d1 = GHandleUtility.DistanceMouseToPoint(Event.current.mousePosition, groundPosition);
                    float d2 = GHandleUtility.DistanceMouseToPoint(Event.current.mousePosition, a.Position);
                    if (d0 <= BEZIER_SELECT_DISTANCE &&
                        d1 > BEZIER_SELECT_DISTANCE &&
                        d2 > BEZIER_SELECT_DISTANCE)
                    {
                        SnapAnchorToSurface(a);
                        GUI.changed = true;
                    }
                }

                float handleSize = HandleUtility.GetHandleSize(a.Position) * 0.2f;
                if (Handles.Button(a.Position, Camera.current.transform.rotation, handleSize, handleSize * 0.5f, Handles.SphereHandleCap))
                {
                    if (GGuiEventUtilities.IsShift)
                    {
                        if (selectedAnchorIndex >= 0 && selectedAnchorIndex < anchors.Count)
                        {
                            instance.Spline.AddSegment(selectedAnchorIndex, i);
                            GUI.changed = true;
                        }
                        selectedAnchorIndex  = i;
                        selectedSegmentIndex = -1;
                        Event.current.Use();
                    }
                    else if (GGuiEventUtilities.IsCtrl)
                    {
                        instance.Spline.RemoveAnchor(i);
                        selectedAnchorIndex  = -1;
                        selectedSegmentIndex = -1;
                        GUI.changed          = true;
                        Event.current.Use();
                    }
                    else
                    {
                        selectedAnchorIndex  = i;
                        selectedSegmentIndex = -1;
                        Event.current.Use();
                    }
                }

                if (i == selectedAnchorIndex)
                {
                    Handles.zTest = UnityEngine.Rendering.CompareFunction.Always;
                    if (Tools.current == Tool.Move)
                    {
                        a.Position = Handles.PositionHandle(a.Position, a.Rotation);
                    }
                    else if (Tools.current == Tool.Rotate)
                    {
                        a.Rotation = Handles.RotationHandle(a.Rotation, a.Position);
                    }
                    else if (Tools.current == Tool.Scale)
                    {
                        a.Scale = Handles.ScaleHandle(a.Scale, a.Position, a.Rotation, HandleUtility.GetHandleSize(a.Position));
                    }
                    instance.transform.position = instance.Spline.Anchors[i].Position;
                }
            }
            Handles.zTest = UnityEngine.Rendering.CompareFunction.Always;
        }