public virtual void MouseRelease(Vector2 mouseGlobalPosition)
 {
     if (ContainsMouse(mouseGlobalPosition))
     {
         OnMouseRelease?.Invoke(this, Args);
         if (ActionOnRelease)
         {
             Action?.Invoke(this, Args);
         }
     }
     else
     {
         OnMouseReleaseOutside?.Invoke(this, Args);
     }
 }
    private void UpdateButton(int button, int infoIndex)
    {
        bool wasPressed = lastMouseDownState[infoIndex];
        bool isPressed  = Input.GetMouseButton(button);

        if (isPressed != wasPressed)
        {
            //Debug.Log("MOUSE " + wasPressed + " -> " + isPressed);
            if (isPressed)
            {
                // click started
                lastMouseDownPos[infoIndex]  = Input.mousePosition;
                lastMouseDownTime[infoIndex] = Time.realtimeSinceStartup;

                OnMousePress?.Invoke(button, Input.mousePosition);
            }
            else
            {
                // click ended
                OnMouseRelease?.Invoke(button, Input.mousePosition);

                Vector3 lastPosition = lastMouseDownPos[infoIndex];
                float   dragDist     = (Input.mousePosition - lastPosition).sqrMagnitude;

                if (lastMouseWasDragging[infoIndex] || dragDist >= minDistDragScreenSqr)
                {
                    // drag
                    //Debug.Log("MOUSE DRAG from " + lastPosition + " to " + Input.mousePosition + " dist " + String.Format("{0,2}", dragDist));
                    OnMouseDrag?.Invoke(button, lastMouseDownPos[infoIndex], Input.mousePosition, Time.realtimeSinceStartup - lastMouseDownTime[infoIndex], true);
                }
                else
                {
                    OnMouseClick?.Invoke(button, lastMouseDownPos[infoIndex], Input.mousePosition);
                }
            }
            lastMouseDownState[infoIndex] = isPressed;
        }

        if (!isPressed)
        {
            lastMouseWasDragging[infoIndex] = false;
        }

        if (isPressed && wasPressed)
        {
            // potential dragging event

            bool isDrag = false;

            if (lastMouseWasDragging[infoIndex])
            {
                isDrag = true;
            }
            else
            {
                Vector3 startPosition = lastMouseDownPos[infoIndex];

                if ((startPosition - Input.mousePosition).sqrMagnitude >= minDistDragScreenSqr)
                {
                    isDrag = true;
                }
            }

            if (isDrag)
            {
                lastMouseWasDragging[infoIndex] = true;

                OnMouseDrag?.Invoke(button, lastMouseDownPos[infoIndex], Input.mousePosition, Time.realtimeSinceStartup - lastMouseDownTime[infoIndex], false);
            }
        }
    }
示例#3
0
 internal void TriggerOnMouseRelease(MouseState state, MouseButton buttons)
 {
     OnMouseRelease?.Invoke(state, buttons);
 }
示例#4
0
 private void OnMouseUp()
 {
     OnMouseRelease?.Invoke(this);
 }