Beispiel #1
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);
            }
        }
Beispiel #2
0
 public void OnDrag(PointerEventData eventData)
 {
     if (OnDragEvent != null)
     {
         OnDragEvent.Invoke(eventData);
     }
 }
Beispiel #3
0
 public void OnDrag(PointerEventData eventData)
 {
     if (interactable)
     {
         OnDragEvent?.Invoke(index);
     }
 }
Beispiel #4
0
 protected override void Awake()
 {
     base.Awake();
     if (onDragEvent == null)
     {
         onDragEvent = new OnDragEvent();
     }
 }
Beispiel #5
0
 public void OnDrag(PointerEventData eventData)
 {
     if (PointerDownCalled == false)
     {
         return;
     }
     ToDrag.position = CachedDragPosition + ((Vector2)Input.mousePosition - CachedMousePosition);
     OnDragEvent?.Invoke(eventData);
 }
Beispiel #6
0
        private void StartDrag()
        {
            currentDragType = DragType.Drag;

            button.interactable = false;
            isDragging          = true;
            SetParent();
            OnDragEvent?.Invoke(true);
            canvasGroup.blocksRaycasts = false;
            dragVisuals.OnDrag(true);
        }
 /// <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);
         }
     }
 }
Beispiel #8
0
        public void StopDrag()
        {
            StopAllCoroutines();
            currentDragType = DragType.Scroll;

            isDragging = false;
            SetParent();
            OnDragEvent?.Invoke(false);
            button.interactable        = true;
            canvasGroup.blocksRaycasts = true;
            dragVisuals.OnDrag(false);
        }
Beispiel #9
0
    public void OnDrag(PointerEventData eventData)
    {
        if (eventData.button != PointerEventData.InputButton.Left)
        {
            return;
        }

        if (zooming_)
        {
            return;
        }

        OnDragEvent.Invoke(eventData);
    }
Beispiel #10
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);
        }
Beispiel #11
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
    }
Beispiel #12
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;
        }
Beispiel #14
0
 public void ClearDragEvent()
 {
     {
         if (OnDragEvent != null)
         {
             Delegate[] invokeList = OnDragEvent.GetInvocationList();
             if (invokeList != null)
             {
                 foreach (Delegate del in invokeList)
                 {
                     OnDragEvent -= (OnDragDlg)del;
                 }
             }
         }
     }
     {
         if (OnBeginDragEvent != null)
         {
             Delegate[] invokeList = OnBeginDragEvent.GetInvocationList();
             if (invokeList != null)
             {
                 foreach (Delegate del in invokeList)
                 {
                     OnBeginDragEvent -= (OnBeginDragDlg)del;
                 }
             }
         }
     }
     {
         if (OnEndDragEvent != null)
         {
             Delegate[] invokeList = OnEndDragEvent.GetInvocationList();
             if (invokeList != null)
             {
                 foreach (Delegate del in invokeList)
                 {
                     OnEndDragEvent -= (OnEndDragDlg)del;
                 }
             }
         }
     }
 }
Beispiel #15
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;
            }
        }
Beispiel #16
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);
     }
 }
Beispiel #17
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);
            }
        }
Beispiel #18
0
 /// <summary>
 /// On drag.
 /// </summary>
 /// <param name="eventData">Pointer event data.</param>
 public void OnDrag(PointerEventData eventData)
 {
     OnDragEvent?.Invoke(eventData);
 }
Beispiel #19
0
 public void OnDrag(PointerEventData eventData)
 {
     //if (item != null)
     OnDragEvent?.Invoke(this);
 }
 void IDragHandler.OnDrag(PointerEventData eventData)
 {
     OnDragEvent.Invoke(eventData);
 }
Beispiel #21
0
 public void OnDrag(BaseEventData eventData)
 {
     OnDragEvent?.Invoke(this);
 }
Beispiel #22
0
 public void OnDrag(PointerEventData eventData) => OnDragEvent?.Invoke(this);