示例#1
0
    private void StopDrag()
    {
        if (_currentDraggable != null)
        {
            _currentDraggable.drag = _initialDragValue;
        }

        _currentDraggable = null;
        IsDragging        = false;
        Cursor.visible    = true;
        Cursor.lockState  = CursorLockMode.None;

        DragStop?.Invoke();
    }
示例#2
0
        /// <summary>
        /// Stop dragging when the user releases the left mouse button
        /// </summary>
        protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
        {
            _userClickedThisElement = false;
            ReleaseMouseCapture(); //Stop absorbing all mouse events

            if (_dragActive)
            {
                _dragActive = false;

                Point  curMouseScreenPos = e.GetPosition(this);
                double xDelta            = curMouseScreenPos.X - _originScreenCoordPosition.X;
                double yDelta            = curMouseScreenPos.Y - _originScreenCoordPosition.Y;

                DragStop?.Invoke(this, new DragMoveEventArgs(e, xDelta, yDelta));
            }

            base.OnMouseLeftButtonUp(e);
        }
示例#3
0
    void InteractiveTemplate(SceneView view, Event ev)
    {
        if (active == null)
        {
            return;
        }

        if (ev.type == EventType.DragUpdated || ev.type == EventType.DragPerform)
        {
            var data = DragAndDrop.GetGenericData("MittEntrance") as GateTags;
            if (data != null)
            {
                dragTemplate = data;
                if (ev.type == EventType.DragUpdated)
                {
                    float d; RaycastHit hit;

                    Vector3 center = activeObject.transform.TransformPoint(active.center);
                    Vector3 normal = -view.camera.transform.forward;
                    if (!ev.shift)
                    {
                        normal = HittUtility.Align(normal);
                    }

                    Plane plane = new Plane(normal, center);
                    Ray   ray   = HittUtility.MouseRay(ev, view);
                    plane.Raycast(ray, out d);
                    Vector3 point = ray.GetPoint(d);

                    if (!ev.shift)
                    {
                        point = HittUtility.Snap(point - center, HandleUtility.GetHandleSize(center) * 0.2f) + center;
                    }
                    if (!(ev.control || ev.command) && Physics.Linecast(point, center, out hit))
                    {
                        point = hit.point;
                    }

                    dragStop = new DragStop()
                    {
                        pos = point, center = center, normal = normal
                    };

                    DragAndDrop.visualMode = DragAndDropVisualMode.Link;
                    ev.Use();
                }
                else
                {
                    {
                        Undo.RecordObject(activeObject, "Add new Entrance");
                        active.AddEntrance(new Entrance()
                        {
                            position = activeObject.transform.InverseTransformPoint(dragStop.pos),
                            rotation = HittUtility.Conjugate(activeObject.transform.rotation) * Quaternion.LookRotation(dragStop.pos - dragStop.center),
                            tag      = dragTemplate.hash
                        });
                        template.Populate();
                    }
                    dragTemplate = null;
                    DragAndDrop.activeControlID = 0;
                    DragAndDrop.AcceptDrag();
                    ev.Use();
                }
            }
        }
        else if (ev.type == EventType.DragExited)
        {
            dragTemplate = null;
        }

        if (ev.type == EventType.Repaint)
        {
            if (dragTemplate != null)
            {
                var r = Mathf.Min(Vector3.Magnitude(dragStop.pos - dragStop.center) * 0.5f, 1);
                var c = dragTemplate.color; Handles.color = c;
                Handles.DrawLine(dragStop.center, dragStop.pos);
                c.a *= 0.5f; Handles.color = c;
                Handles.DrawWireDisc(dragStop.center, dragStop.normal, r);
                c.a *= 0.2f; Handles.color = c;
                Handles.DrawSolidDisc(dragStop.center, dragStop.normal, r);
            }
        }
    }