Esempio n. 1
0
    public void OnPointerDown(PointerEventData data)
    {
        pressPosition      = myRb.position;
        timeWhenPressed    = Time.time;
        isPressed          = true;
        draggingTouchIndex = data.pointerId;
#if (UNITY_EDITOR || MOUSEINPUT)
        pressOffsetFromCenter = (Input.mousePosition - this.transform.position);
#else
        pressOffsetFromCenter = (Vector3)InputEx.GetTouchById(draggingTouchIndex).Value.position - this.transform.position;
#endif
    }
Esempio n. 2
0
    protected virtual void Update()
    {
        if (isPressed && DragTouchEnded())
        {
            PointerUp();
        }

        if (DetectPointerDown())
        {
            PointerDown();
        }

        if (isPressed)
        {
            if (Time.time - timeWhenPressed > buttonDisable_Delay)
            {
                disableButtonOnDrag.IfNotNull(b => b.interactable = false);
            }
            if ((myRb.position - pressPosition).magnitude > minDragDistanceToDisableButton)
            {
                disableButtonOnDrag.IfNotNull(b => b.interactable = false);
            }

            if (Time.time - timeWhenPressed > dragDelay)
            {
#if (UNITY_EDITOR || MOUSEINPUT)
                Vector3 position = (Vector3)Input.mousePosition;
                myRb.MovePosition(position - pressOffsetFromCenter);
#else
                if (InputEx.GetTouchById(draggingTouchIndex).HasValue)
                {
                    Vector3 position = (Vector3)InputEx.GetTouchById(draggingTouchIndex).Value.position;
                    myRb.MovePosition(position - pressOffsetFromCenter);
                }
#endif
            }
        }
        if (prevPosition.Count >= prevPositionsBuffer)
        {
            prevPosition.RemoveAt(0);
        }
        prevPosition.Add(this.transform.position);
        if (useDrag)
        {
            myRb.velocity *= releaseDrag;
        }
    }
Esempio n. 3
0
    public void PointerDown()
    {
        pressPosition   = myRb.position;
        timeWhenPressed = Time.time;
        isPressed       = true;
#if (UNITY_EDITOR || MOUSEINPUT)
        pressOffsetFromCenter = (Input.mousePosition - this.transform.position);
#else
        pressOffsetFromCenter = (Vector3)InputEx.GetTouchById(draggingTouchIndex).Value.position - this.transform.position;
#endif
        if (makeKinematicWhileDragging)
        {
            rbToBodyType.Clear();
            foreach (Rigidbody2D rb in this.GetComponentsInChildren <Rigidbody2D>())
            {
                rbToBodyType.Add(rb, rb.bodyType);
                rb.bodyType = RigidbodyType2D.Kinematic;
            }
        }
    }