Esempio n. 1
0
 protected override void OnMouseMove(MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Left)
     {
         var shift = new Point(e.Location.X - mouseDown.X, e.Location.Y - mouseDown.Y);
         mouseDown = e.Location;
         //
         if (dragged != null)
         {
             dragged.Drag(shift);//двигаем объект
         }
         else
         {
             offset = new Point(offset.X + shift.X, offset.Y + shift.Y);//сдвигаем канвас
         }
         Invalidate();
     }
 }
        protected override void OnMouseMove(MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                var shift =
                    new PointF(e.Location.X - _mouseDown.X, e.Location.Y - _mouseDown.Y);
                _mouseDown = e.Location;
                if (_dragged != null)
                {
                    _dragged.Drag(shift);
                }
                else
                {
                    _offset = new PointF(_offset.X + shift.X, _offset.Y + shift.Y);
                }
                Invalidate();
            }
            var p      = ToClient(e.Location);
            var hitted = _nodes.FirstOrDefault(n => n.Hit(p));

            Cursor = hitted != null ? Cursors.Hand : Cursors.Default;
        }
Esempio n. 3
0
    void FixedUpdate()
    {
        if (!Input.GetMouseButtonDown(0))
        {
            return;
        }

        Camera mainCamera = Camera.main;

        RaycastHit[] hits;
        hits = Physics.RaycastAll(mainCamera.ScreenPointToRay(Input.mousePosition).origin,
                                  mainCamera.ScreenPointToRay(Input.mousePosition).direction, 100,
                                  Physics.DefaultRaycastLayers);

        int minDragableLayer = (int)DragPriority.SceneObj;
        int dragIndex = -1, minLayer = int.MaxValue;

        for (int i = 0; i < hits.Length; ++i)
        {
            GameObject obj = hits[i].collider.gameObject;
            //在允许拖拽的layer中,选择最小的那个
            if (obj.layer >= minDragableLayer && obj.layer < minLayer)
            {
                minLayer  = obj.layer;
                dragIndex = i;
            }
        }
        if (dragIndex > -1)
        {
            GameObject dragObj  = hits[dragIndex].collider.gameObject;
            IDragable  dragable = dragObj.GetComponent <IDragable>();
            if (dragable != null)
            {
                dragable.Drag();
            }
        }
    }