Example #1
0
 public void OnDrag(PointerEventData eventData)
 {
     if (interactable)
     {
         OnDragEvent?.Invoke(index);
     }
 }
Example #2
0
 public void OnDrag(PointerEventData eventData)
 {
     if (OnDragEvent != null)
     {
         OnDragEvent.Invoke(eventData);
     }
 }
Example #3
0
        /// <summary>
        /// Raises the drag event.
        /// </summary>
        /// <param name="eventData">Event data.</param>
        public virtual void OnDrag(PointerEventData eventData)
        {
            if (eventData.button != DragInputButton)
            {
                return;
            }

            if (canvas == null)
            {
                throw new MissingComponentException(gameObject.name + " not in Canvas hierarchy.");
            }
            Vector2 cur_pos;
            Vector2 prev_pos;

            RectTransformUtility.ScreenPointToLocalPointInRectangle(drag, eventData.position, eventData.pressEventCamera, out cur_pos);
            RectTransformUtility.ScreenPointToLocalPointInRectangle(drag, eventData.position - eventData.delta, eventData.pressEventCamera, out prev_pos);

            var new_pos = new Vector3(
                drag.localPosition.x + (cur_pos.x - prev_pos.x),
                drag.localPosition.y + (cur_pos.y - prev_pos.y),
                drag.localPosition.z);

            drag.localPosition = new_pos;

            //分发OnDrag消息
            if (OnDragEvent != null)
            {
                OnDragEvent.Invoke(eventData);
            }
        }
Example #4
0
 void Drop()
 {
     draggedHold = false;
     if (EventObserver.instance.happeningEvent == Events.DragMultiplePixelsStart ||
         EventObserver.instance.happeningEvent == Events.DragMultiplePixels)
     {
         // Group.UngroupOneByOne();
         if (_cachedSelectedPixels.IsNotNull())
         {
             _cachedSelectedPixels.Clear();
         }
     }
     else
     {
         // var closestPixel = GetClosestPixel();
         // if (closestPixel.IsNotNull())
         // {
         //     var closestAnchor = GetClosestAnchor(closestPixel);
         //     if (closestAnchor.IsNotNull())
         //     {
         //         transform.position = closestAnchor.transform.position;
         //     }
         // }
     }
     if (onDrop.IsNotNull())
     {
         onDrop.Invoke(this, transform.position);
     }
 }
Example #5
0
    public override void OnTouch()
    {
        if (!isTouched)
        {
            isTouched           = true;
            startTouchPosScreen = TouchObjectsController.Instance.GetTouchPointScreen();
            startPosition       = transform.position;

            Rigid.useGravity = false;
            GetComponent <Collider>().enabled = false;
            if (onDragEvent != null)
            {
                onDragEvent.Invoke(true);
            }
        }
        base.OnTouch();
    }
Example #6
0
 public void OnDrag(PointerEventData eventData)
 {
     if (PointerDownCalled == false)
     {
         return;
     }
     ToDrag.position = CachedDragPosition + ((Vector2)Input.mousePosition - CachedMousePosition);
     OnDragEvent?.Invoke(eventData);
 }
Example #7
0
        public void OnDrag(PointerEventData eventData)
        {
            if (rect == null)
            {
                return;
            }

            rect.position = windowStart + (Vector3)(eventData.position - mouseStart);

            DragEvent.Invoke(rect);
        }
Example #8
0
 /// <summary>
 /// Every frame on this item drag
 /// </summary>
 /// <param name="data"></param>
 public virtual void OnDrag(PointerEventData data)
 {
     if (icon != null)
     {
         icon.transform.position = Input.mousePosition;                          // Item's icon follows to cursor
         if (OnDragEvent != null)
         {
             OnDragEvent.Invoke(data);
         }
     }
 }
Example #9
0
        private void StartDrag()
        {
            currentDragType = DragType.Drag;

            button.interactable = false;
            isDragging          = true;
            SetParent();
            OnDragEvent?.Invoke(true);
            canvasGroup.blocksRaycasts = false;
            dragVisuals.OnDrag(true);
        }
Example #10
0
        public void StopDrag()
        {
            StopAllCoroutines();
            currentDragType = DragType.Scroll;

            isDragging = false;
            SetParent();
            OnDragEvent?.Invoke(false);
            button.interactable        = true;
            canvasGroup.blocksRaycasts = true;
            dragVisuals.OnDrag(false);
        }
Example #11
0
    public void OnDrag(PointerEventData eventData)
    {
        if (onDragEvent != null)
        {
            onDragEvent.Invoke(eventData);
        }
        if (!arrangeable)
        {
            return;
        }
        var position = eventData.position;

        if (canvas.renderMode == RenderMode.ScreenSpaceCamera ||
            canvas.renderMode == RenderMode.WorldSpace)
        {
            position = canvas.worldCamera.ScreenToWorldPoint(position);
        }
        if (useIcon)
        {
            if (draggableIcon != null)
            {
                draggableIcon.transform.position = position;
                foreach (var item in items)
                {
                    if (!RectTransformUtility.RectangleContainsScreenPoint(item.GetComponent <RectTransform>(), position))
                    {
                        item.transform.localScale         = Vector3.one;
                        item.GetComponent <Image>().color = originalColor;
                        continue;
                    }
                    item.transform.localScale         = Vector3.one * 1.1f;
                    item.GetComponent <Image>().color = hoverColor;
                }
            }
        }
        else
        {
            if (draggableObject != null)
            {
                draggableObject.transform.position = position;
                for (var i = 0; i < items.Length; i++)
                {
                    var item = items[i];
                    if (RectTransformUtility.RectangleContainsScreenPoint(item.GetComponent <RectTransform>(), position))
                    {
                        transform.SetSiblingIndex(item.transform.GetSiblingIndex());
                    }
                }
            }
        }
    }
Example #12
0
    public void OnDrag(PointerEventData eventData)
    {
        if (eventData.button != PointerEventData.InputButton.Left)
        {
            return;
        }

        if (zooming_)
        {
            return;
        }

        OnDragEvent.Invoke(eventData);
    }
Example #13
0
 public void OnEndDrag(PointerEventData eventData)
 {
     if (!draggable)
     {
         return;
     }
     if (draggedInstance.IsNotNull())
     {
         if (onDragEndEvent.IsNotNull())
         {
             onDragEndEvent.Invoke(this, eventData.position);
         }
         Destroy(draggedInstance.gameObject);
     }
     dragging = false;
 }
Example #14
0
        public void OnDrag(PointerEventData eventData)
        {
            var delta            = eventData.delta;
            var relativePosition = (Vector2)transform.position - eventData.position;
            var theta            = Mathf.Rad2Deg * Mathf.Atan2(relativePosition.y, relativePosition.x);
            var fixedDelta       = delta.RotateAroundZ(Vector3.zero, (360 - theta) % 360);
            var rotationAmount   = delta.sqrMagnitude * Mathf.Sign(fixedDelta.y) * speedFactor;

            rotationAmount = Mathf.Clamp(rotationAmount, -deltaClamp, deltaClamp);
            if (Math.Abs(rotationAmount) < dragThreshold)
            {
                return;
            }
            RadialUI.RotateRadial(-rotationAmount);
            eventData.delta = fixedDelta;
            OnDragEvent?.Invoke(eventData);
        }
Example #15
0
    private void OnDrag(InputAction.CallbackContext callbackContext)
    {
        if (IsInputNotValidState())
        {
            return;
        }

        if (isPress == false)
        {
            return;
        }

        OnDragEvent?.Invoke(touchPosition.ReadValue <Vector2>());

#if DEBUGGING
        Debug.Log($"Dragging {touchPosition.ReadValue<Vector2>()}");
#endif
    }
Example #16
0
        public void OnDrag(PointerEventData eventData)
        {
            DragEvent sDragEvent = new DragEvent(this, EDragState.Stay, Input.mousePosition);

            foreach (var pDragLogic_KeyPair in _mapDragLogic)
            {
                if (ContainEnumFlag(pDragLogic_KeyPair.Key, EDragState.Stay) == false)
                {
                    continue;
                }

                foreach (var pLogic in pDragLogic_KeyPair.Value)
                {
                    pLogic.OnDragEvent(sDragEvent);
                }
            }

            OnDragEvent?.Invoke(sDragEvent);
        }
        public void Update()
        {
            var touching = BaseInput.IsTouching(true);

            if (touching)
            {
                var touch0Position = BaseInput.GetTouchPosition(0).y;
                var touch1Position = BaseInput.GetTouchPosition(1).y;
                var position       = (touch0Position + touch1Position) * 0.5f;

                if (!Panning)
                {
                    if (!WasTouching)
                    {
                        LastPosition = position;
                    }

                    var delta = Mathf.Abs(position - LastPosition);

                    if (!Rotating && delta >= Threshold)
                    {
                        LastPosition = position;
                        Panning      = true;
                    }
                }
                if (Panning)
                {
                    var delta = position - LastPosition;
                    OnDragEvent.Invoke(Vector3.up * (delta * Ratio));

                    LastPosition = position;
                }
            }

            if (!touching && Panning)
            {
                Panning = false;
                OnReleaseEvent.Invoke();
            }

            WasTouching = touching;
        }
Example #18
0
        private void Update()
        {
            if (!Dragging || Selected == null)
            {
                return;
            }

            if (Raycast(BaseInput.GetTouchPosition(), out var planePosition))
            {
                var delta = planePosition - LastPosition;

                if (Mathf.Approximately(delta.x, 0) && Mathf.Approximately(delta.y, 0) && Mathf.Approximately(delta.z, 0))
                {
                    return;
                }

                OnDragEvent.Invoke(delta);

                LastPosition = planePosition;
            }
        }
Example #19
0
 /// <summary>
 /// 拖拽
 /// </summary>
 /// <param name="_eventData">参数</param>
 public void OnDrag(PointerEventData _eventData)
 {
     if (_eventData.dragging)
     {
         RectTransform canvas        = (RectTransform)mMaskableGraphic.canvas.transform;
         Vector2       mouseUguiPos  = Vector2.zero;
         RectTransform dragTransform = (RectTransform)_eventData.pointerDrag.transform;
         if (RectTransformUtility.RectangleContainsScreenPoint(canvas, _eventData.position, _eventData.pressEventCamera))
         {//如果鼠标在屏幕内
             bool isRect = RectTransformUtility.ScreenPointToLocalPointInRectangle(
                 canvas, _eventData.position, _eventData.pressEventCamera, out mouseUguiPos);
             if (isRect)//如果在
             {
                 //设置图片的ugui坐标与鼠标的ugui坐标保持不变
                 dragTransform.anchoredPosition = mOffset + mouseUguiPos;
                 dragTransform.FixedPositionInCanvas(canvas);
             }
         }
         OnDragEvent?.Invoke(this, _eventData);
     }
 }
Example #20
0
        //鼠标拖拽时的操作;
        public void OnDrag(PointerEventData eventData)
        {
            float       delta = eventData.delta.x / Screen.width;
            const float ffff  = 0.06f;
            float       ad    = Mathf.Abs(delta);
            float       t     = Mathf.Sign(delta) * (ad * ad + 2f * ad * ffff);

            mAcc = mAcc * 0.2f + 1E4f * t / (Time.time - mPrevDrag);
            if (mAcc >= 0f)
            {
                mAcc = Mathf.Lerp(k_friction, k_max_acc, mAcc / k_max_acc);
            }
            else
            {
                mAcc = Mathf.Lerp(-k_friction, -k_max_acc, -mAcc / k_max_acc);
            }
            //Log.dtf("zw", "acc : {0}", mAcc);
            mPrevDrag = Time.time;
            if (OnDragEvent != null)
            {
                OnDragEvent.Invoke(eventData);
            }
        }
Example #21
0
 /// <summary>
 /// On drag.
 /// </summary>
 /// <param name="eventData">Pointer event data.</param>
 public void OnDrag(PointerEventData eventData)
 {
     OnDragEvent?.Invoke(eventData);
 }
Example #22
0
 public void OnDrag(PointerEventData eventData)
 {
     //if (item != null)
     OnDragEvent?.Invoke(this);
 }
Example #23
0
    void DragStart()
    {
        var hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);

        if (hit.collider != null)
        {
            // if hitting the pivot of group
            var hittingPivot = hit.transform.GetComponent <GroupPivot>();
            if (hittingPivot.IsNotNull())
            {
                return;
            }
        }
        // if this pixel is non-selecting, then deselecting all another one
        if (!selecting && !SelectObjectManager.instance.multipleChoice)
        {
            var pixelsWithoutThis = pixelManager.GetPixels(x => x.id != this.id && x.selecting);
            if (pixelsWithoutThis.Any())
            {
                var pixelsWithoutThisToArray = pixelsWithoutThis.ToArray();
                foreach (var p in pixelsWithoutThisToArray)
                {
                    p.Deselect();
                }
                pixelsWithoutThisToArray = null;
            }
        }
        var selectedPixels        = pixelManager.GetPixels(x => x.selecting);
        var countOfSelectedPixels = selectedPixels.Count();
        var realPosition          = transform.localPosition;
        var mousePosition         = Camera.main.ScreenToWorldPoint(Input.mousePosition);

        // if multipleChoice was actived, then denying dragging start of group
        if (countOfSelectedPixels > 1 && !SelectObjectManager.instance.multipleChoice)
        {
            if (_cachedSelectedPixels.IsNull())
            {
                _cachedSelectedPixels = new List <Pixel>();
            }
            _cachedSelectedPixels.Clear();
            _cachedSelectedPixels = selectedPixels.ToList();
            // var selectedPoints = _cachedSelectedPixels.Select(x => x.transform.position).ToArray();
            // var centerPoint = TransformUtility.ComputeCenterPoint(selectedPoints);
            // var selectedPosition = centerPoint.ToVector2();
            // realPosition = selectedPosition;
            // selectedPoints = null;
            _anchorMovePoint = mousePosition;
            // Group.Create();
            // var group = GetFirstGroup();
            // if (group.IsNotNull())
            // {
            //     realPosition = group.transform.localPosition;
            // }

            realPosition = transform.position;
            EventObserver.instance.happeningEvent = Events.DragMultiplePixelsStart;
        }
        else
        {
            // if pixel has been in any group, then getting world position of it for computing accurately.
            if (group.IsNotNull())
            {
                var group = GetFirstGroup();
                if (group.IsNotNull())
                {
                    realPosition = group.transform.localPosition;
                }
            }
            _anchorMovePoint = realPosition - mousePosition;
            EventObserver.instance.happeningEvent = Events.DragPixelStart;
        }
        // _anchorMovePoint = realPosition - mousePosition;
        // if multipleChoice was actived, then denying of dragging
        draggedHold = true && !SelectObjectManager.instance.multipleChoice;
        if (onDragStart.IsNotNull())
        {
            onDragStart.Invoke(this, transform.position);
        }
        selectedPixels = null;
    }
Example #24
0
    void Drag()
    {
        if (draggedHold)
        {
            if (Input.GetAxis("Mouse X") != 0 || Input.GetAxis("Mouse Y") != 0)
            {
                if (EventObserver.instance.happeningEvent == Events.DragPixelStart)
                {
                    EventObserver.instance.happeningEvent = Events.DragPixel;
                }
                if (EventObserver.instance.happeningEvent == Events.DragMultiplePixelsStart)
                {
                    EventObserver.instance.happeningEvent = Events.DragMultiplePixels;
                }

                // move if mouse has any movement
                var mousePosition      = Input.mousePosition;
                var worldMousePosition = Camera.main.ScreenToWorldPoint(mousePosition);
                var targetPosition     = worldMousePosition.ToVector2();

                if (EventObserver.instance.happeningEvent == Events.DragMultiplePixels)
                {
                    if (!_cachedSelectedPixels.Any())
                    {
                        return;
                    }
                    targetPosition = targetPosition.Snap2();
                    var distanceDelta           = targetPosition - _anchorMovePoint;
                    var firstOuterGroupSelected = new List <int>();
                    _cachedSelectedPixels.ForEach(pixel =>
                    {
                        var firstGroup = pixel.GetFirstGroup();
                        if (firstGroup.IsNotNull())
                        {
                            if (firstOuterGroupSelected.Contains(firstGroup.id))
                            {
                                return;
                            }
                            firstOuterGroupSelected.Add(firstGroup.id);
                            var firstGroupTransform      = firstGroup.transform;
                            var firstGroupPosition       = firstGroupTransform.position;
                            var snapPosition             = firstGroupPosition + new Vector3(distanceDelta.x, distanceDelta.y, firstGroupPosition.z);
                            firstGroupTransform.position = snapPosition.ToVector2().Snap2();
                        }
                        else
                        {
                            var pixelTransform      = pixel.transform;
                            var pixelPosition       = pixelTransform.position;
                            var snapPosition        = pixelPosition + new Vector3(distanceDelta.x, distanceDelta.y, pixelPosition.z);
                            pixelTransform.position = snapPosition.ToVector2().Snap2();
                        }
                    });
                    firstOuterGroupSelected.Clear();
                    _anchorMovePoint = targetPosition;
                }
                else
                {
                    var realPosition = targetPosition + _anchorMovePoint;
                    realPosition = realPosition.Snap2();
                    if (group.IsNotNull())
                    {
                        // if pixel has been in a group, then move that group
                        var group = GetFirstGroup();
                        if (group.IsNotNull())
                        {
                            group.transform.position = realPosition;
                        }
                    }
                    else
                    {
                        // if pixel was in normal state
                        transform.position = realPosition;
                    }
                    if (onDrag.IsNotNull())
                    {
                        onDrag.Invoke(this, realPosition);
                    }
                }
            }
        }
    }
 void IDragHandler.OnDrag(PointerEventData eventData)
 {
     OnDragEvent.Invoke(eventData);
 }
Example #26
0
 public void OnDrag(BaseEventData eventData)
 {
     OnDragEvent?.Invoke(this);
 }
Example #27
0
 public void OnDrag(PointerEventData eventData) => OnDragEvent?.Invoke(this);
 public virtual void OnDrag(PointerEventData eventData)
 {
     onDragEvent.Invoke(eventData);
 }