예제 #1
0
        private void Start()
        {
            Vector3 posLocal = EditWindow.MouseGlobalToLocal(Input.mousePosition);

            for (int i = 0; i < lastPosition.Length; i++)
            {
                lastPosition[i] = posLocal;
            }
        }
예제 #2
0
        private void UpdateButton(int btn)
        {
            var mousePosLocal = EditWindow.MouseGlobalToLocal(Input.mousePosition);

            if (EditWindow.MouseInEditWindow)
            {
                if (Input.GetMouseButtonDown(btn))
                {
                    Cursor.lockState = CursorLockMode.Confined;
                    FireMouseDown(mousePosLocal, btn);
                    mouseButtonDown[btn]   = true;
                    mouseButtonMoved[btn]  = false;
                    mouseDownPosition[btn] = mousePosLocal;
                }
            }
            if (Input.GetMouseButtonUp(btn))
            {
                Cursor.lockState = CursorLockMode.None;
                FireMouseUp(mousePosLocal, btn, EditWindow.MouseInEditWindow);
                if (EditWindow.MouseInEditWindow && mouseButtonDown[btn] && !mouseButtonMoved[btn])
                {
                    FireClick(mousePosLocal, btn);
                }
                mouseButtonDown[btn] = false;
                if (isDragging[btn])
                {
                    FireEndDrag(mousePosLocal, btn);
                    isDragging[btn] = false;
                }
            }

            if (Input.GetMouseButton(btn))
            {
                if (isDragging[btn])
                {
                    //var offset = new Vector3(Input.GetAxis("Mouse X") * 5, Input.GetAxis("Mouse Y") * 5, 0);
                    var offset = mousePosLocal - lastPosition[btn];
                    FireDrag(lastPosition[btn], mousePosLocal, offset, btn);
                }
                else if (mouseButtonDown[btn] && EditWindow.IsInEditWindow(mouseDownPosition[btn])) //only start drag if mouse down position was inside window
                {
                    var offsetSinceDown   = mousePosLocal - mouseDownPosition[btn];
                    var distanceSinceDown = offsetSinceDown.magnitude;
                    if (distanceSinceDown >= distanceTillDrag)
                    {
                        mouseButtonMoved[btn] = true;
                        FireBeginDrag(mouseDownPosition[btn], btn);
                        isDragging[btn] = true;
                        FireDrag(mouseDownPosition[btn], mousePosLocal, offsetSinceDown, btn);
                    }
                }
            }

            lastPosition[btn] = mousePosLocal;
        }