private Vector3 MoveHandle(HashSet <int> vertices, Vector3 position, Vector3 axis, ref bool moved, float s)
        {
            float handleSize = HandleUtility.GetHandleSize(position) * size;

            CustomHandles.HandleResult result = CustomHandles.HandleResult.None;

            Vector3 dragPos = CustomHandles.DragHandle(position, axis,
                                                       handleSize, Handles.ConeHandleCap, out result, ctrl, s);

            if (result == CustomHandles.HandleResult.Drag)
            {
                brush.undone = true;
                Undo.RecordObject(brush, "Brush Edit");
                Vector3 offset = dragPos - position;

                foreach (var vert in vertices)
                {
                    brush.mesh.vertices[vert].position += offset;
                }

                brush.undone = false;

                brush.dirty = true;
                brush.Update();
            }

            moved |= result != CustomHandles.HandleResult.None;

            return(dragPos);
        }
        private Vector3 ScaleHandle(HashSet <int> vertices, Vector3 position, Vector3 axis, ref bool moved, ref float scaleMvt, float s)
        {
            float handleSize = HandleUtility.GetHandleSize(position) * size;

            CustomHandles.HandleResult result = CustomHandles.HandleResult.None;

            Vector3 dragPos = CustomHandles.DragHandle(position, axis,
                                                       handleSize, Handles.SphereHandleCap, out result, ctrl, s);

            if (result == CustomHandles.HandleResult.Drag)
            {
                brush.undone = true;
                Undo.RecordObject(brush, "Brush Edit");
                Vector3 offset = dragPos - position;

                float amt = Vector3.Dot(offset, axis);
                scaleMvt += amt;
                Vector3 c = brush.mesh.GetVerticesCenter(vertices);

                foreach (var vert in vertices)
                {
                    Vector3 v = brush.mesh.vertices[vert].position;
                    v -= c;
                    Vector3 onAxis  = Vector3.Project(v, axis);
                    Vector3 offAxis = v - onAxis;
                    onAxis *= 1 + amt;

                    v = c + onAxis + offAxis;
                    brush.mesh.vertices[vert].position = v;
                }

                brush.undone = false;

                brush.dirty = true;
                brush.Update();
            }
            else if (result == CustomHandles.HandleResult.Release)
            {
                scaleMvt = 0;
            }

            moved |= result != CustomHandles.HandleResult.None;

            return(dragPos);
        }
        private void SizeHandle(Vector3 axis, Vector3 axisN, Color color)
        {
            Transform transform = brush.transform;

            CustomHandles.HandleResult result;

            Vector3 worldAxis = transform.TransformDirection(axisN);

            Vector3 center = transform.rotation * (brush.size / 2);

            Vector3 handlePos  = transform.position + center + Vector3.Dot(axis, brush.size / 2) * worldAxis;
            float   handleSize = HandleUtility.GetHandleSize(handlePos) * size;

            handlePos += worldAxis * 1;

            Handles.color = color;

            Vector3 dragPos = CustomHandles.DragHandle(handlePos, worldAxis,
                                                       handleSize, Handles.ConeHandleCap, out result, ctrl);

            float drag = Vector3.Dot(dragPos - handlePos, worldAxis);

            float diff = -Vector3.Dot(axis, axisN);

            diff = (1.0f + diff) / 2.0f;

            if (result == CustomHandles.HandleResult.Drag)
            {
                brush.undone = true;
                Undo.RecordObject(brush, "Brush Edit");
                Undo.RecordObject(brush.transform, "Brush Edit");

                brush.transform.position += worldAxis * drag * diff;

                brush.size  += axis * drag;
                brush.undone = false;

                if (drag != 0)
                {
                    brush.Update();
                }
            }
        }