示例#1
0
 internal protected virtual void TriggerOnMouseClick(Component sender, int x, int y, MouseButton button)
 {
     if (OnMouseClick != null)
     {
         OnMouseClick.Invoke(new MouseButtonEventArgs(sender, x, y, button));
     }
 }
示例#2
0
        private void Hook_MouseUp(object sender, MouseEventArgs e)
        {
            Task.Run(async() =>
            {
                if (!Enabled || !configuration.CloseOverlayWithMouse)
                {
                    return;
                }

                if (OnMouseClick != null)
                {
                    await OnMouseClick.Invoke(e.X, e.Y);
                }
            });
        }
示例#3
0
    private void MouseUp(int buttonId, Vector3 mousePosition)
    {
        currentClickIsOnUi = false;

        if (!canInputBeMade)
        {
            return;
        }

        if (!BuilderInWorldUtils.IsPointerOverUIElement() && !BuilderInWorldUtils.IsPointerOverMaskElement(layerToStopClick))
        {
            OnMouseUp?.Invoke(buttonId, mousePosition);
            if (Vector3.Distance(mousePosition, lastMousePosition) >= movementClickThreshold)
            {
                return;
            }
            if (Time.unscaledTime >= lastTimeMouseDown + msClickThreshold / 1000)
            {
                return;
            }
            OnMouseClick?.Invoke(buttonId, mousePosition);
        }
    }
    private void MouseUp(int buttonId, Vector3 mousePosition)
    {
        if (!isEditModeActive)
        {
            return;
        }

        if (currentClickIsOnUi)
        {
            OnMouseClickOnUI?.Invoke(buttonId, mousePosition);
            currentClickIsOnUi = false;
            return;
        }

        if (!canInputBeMade)
        {
            return;
        }

        if (!BIWUtils.IsPointerOverUIElement())
        {
            OnMouseUp?.Invoke(buttonId, mousePosition);
            if (Vector3.Distance(mousePosition, lastMousePosition) >= MOVEMENT_CLICK_THRESHOLD)
            {
                return;
            }
            if (Time.unscaledTime >= lastTimeMouseDown + MS_CLICK_THRESHOLD / 1000)
            {
                return;
            }
            OnMouseClick?.Invoke(buttonId, mousePosition);
        }
        else
        {
            OnMouseUpOnUI?.Invoke(buttonId, mousePosition);
        }
    }
示例#5
0
    public void NextState()
    {
        Debug.Log("next state");

        switch (state)
        {
        case GameState.BEFOREROLLDICE:
            break;

        case GameState.AFTERDICE:
            break;

        case GameState.ENDOFGAME:
            break;

        case GameState.WAIT:
            OnWaitClick?.Invoke(this, EventArgs.Empty);
            break;

        case GameState.NORMAL:
            OnMouseClick?.Invoke(this, transform);
            break;
        }
    }
示例#6
0
 private void OnMouseUpAsButton()
 {
     OnMouseClick?.Invoke();
 }
示例#7
0
        private void Update()
        {
            if (CheckKey(KeyCode.W))
            {
                OnWPressed?.Invoke(this, EventArgs.Empty);
                KeyEventArgs args = new KeyEventArgs(KeyCode.W);
                OnKeyPressed?.Invoke(this, args);
                OnMovementKeyPressed?.Invoke(this, args);
            }
            if (CheckKey(KeyCode.A))
            {
                OnAPressed?.Invoke(this, EventArgs.Empty);
                KeyEventArgs args = new KeyEventArgs(KeyCode.A);
                OnKeyPressed?.Invoke(this, args);
                OnMovementKeyPressed?.Invoke(this, args);
            }
            if (CheckKey(KeyCode.S))
            {
                OnSPressed?.Invoke(this, EventArgs.Empty);
                KeyEventArgs args = new KeyEventArgs(KeyCode.S);
                OnKeyPressed?.Invoke(this, args);
                OnMovementKeyPressed?.Invoke(this, args);
            }
            if (CheckKey(KeyCode.D))
            {
                OnDPressed?.Invoke(this, EventArgs.Empty);
                KeyEventArgs args = new KeyEventArgs(KeyCode.D);
                OnKeyPressed?.Invoke(this, args);
                OnMovementKeyPressed?.Invoke(this, args);
            }
            if (CheckKey(KeyCode.Space))
            {
                OnSpacePressed?.Invoke(this, EventArgs.Empty);
                KeyEventArgs args = new KeyEventArgs(KeyCode.Space);
                OnKeyPressed?.Invoke(this, args);
            }

            RunKey(KeyCode.G);
            RunKey(KeyCode.H);
            RunKey(KeyCode.Q);
            RunKey(KeyCode.Escape);

            var scrollDelta = Input.GetAxis("Mouse ScrollWheel");

            if (scrollDelta != 0.0F)
            {
                ScrollEventArgs args;
                if (scrollDelta > 0.0F)
                {
                    args = new ScrollEventArgs(true);
                    OnScrollUp?.Invoke(this, EventArgs.Empty);
                }
                else
                {
                    args = new ScrollEventArgs(false);
                    OnScrollDown?.Invoke(this, EventArgs.Empty);
                }
                OnScroll?.Invoke(this, args);
            }

            if (CheckMouseSingle(MouseButton.LEFT))
            {
                ClickEventArgs args = new ClickEventArgs(MouseButton.LEFT, Input.mousePosition);
                OnMouseClick?.Invoke(this, args);
                OnLeftMouseClick?.Invoke(this, args);
            }
            if (CheckMouseSingle(MouseButton.RIGHT))
            {
                ClickEventArgs args = new ClickEventArgs(MouseButton.RIGHT, Input.mousePosition);
                OnMouseClick?.Invoke(this, args);
                OnRightMouseClick?.Invoke(this, args);
            }
        }
示例#8
0
        // Unity Events ------------------------------------------------------------------------------------------------
        // Pointer

        public void OnPointerClick(PointerEventData eventData)
        {
            // starts build phase
            OnMouseClick?.Invoke(Building);
        }
示例#9
0
文件: Mouse.cs 项目: nchos88/SOA
        private void HookMouseCallback(HookData hookData)
        {
            MouseEventInformation info = MouseEventInformation.Get(hookData);

            int          mx     = info.X;
            int          my     = info.Y;
            MouseButtons button = info.Button;

            // 마우스 다운
            if (info.IsMouseDown)
            {
                if (IsDoubleClick(info))
                {
                    info = info.ToDobuleClickMouseEventInformation();
                }

                OnMouseDown?.Invoke(mx, my, button);

                if (info.Clicks == 2)
                {
                    m_DoubleButton |= info.Button;
                }

                if (info.Clicks == 1)
                {
                    m_SingleButton |= button;
                }
            }

            // 마우스 업
            if (info.IsMouseUp)
            {
                OnMouseUp?.Invoke(mx, my, button);

                // 마우스 클릭
                if ((m_SingleButton & button) != MouseButtons.None)
                {
                    OnMouseClick?.Invoke(mx, my, button);
                    m_SingleButton &= ~button;
                }

                // 마우스 더블 클릭
                if ((m_DoubleButton & button) != MouseButtons.None)
                {
                    OnMouseDoubleClick?.Invoke(mx, my, button);
                    m_DoubleButton &= ~button;
                }

                if (info.Clicks == 2)
                {
                    m_PreviousClickedButton = MouseButtons.None;
                    m_PreviousClickedTime   = 0;
                    m_PreviousClickedX      = m_DefaultPositionXY;
                    m_PreviousClickedY      = m_DefaultPositionXY;
                }

                if (info.Clicks == 1)
                {
                    m_PreviousClickedButton = info.Button;
                    m_PreviousClickedTime   = info.Timestamp;
                    m_PreviousClickedX      = mx;
                    m_PreviousClickedY      = my;
                }
            }

            // 마우스 스크롤
            if (info.IsMouseWheelScrolled)
            {
                OnMouseWheel?.Invoke(mx, my, button, info.Delta > 0 ? 1 : -1);
            }

            // 마우스 이동
            if (IsMoved(mx, my))
            {
                m_PreviousX = mx;
                m_PreviousY = my;

                OnMouseMove?.Invoke(mx, my, button);
            }

            // 마우스 드래그
            if ((m_SingleButton & MouseButtons.Left) != MouseButtons.None)
            {
                if (m_DragStartPositionX == m_DefaultPositionXY && m_DragStartPositionY == m_DefaultPositionXY)
                {
                    m_DragStartPositionX = mx;
                    m_DragStartPositionY = my;
                }

                // 마우스 드래그 스타트
                if (m_dragMode == false)
                {
                    bool isXDragging = Math.Abs(mx - m_DragStartPositionX) > m_SystemDragX;
                    bool isYDragging = Math.Abs(my - m_DragStartPositionY) > m_SystemDragY;

                    m_dragMode = isXDragging || isYDragging;

                    if (m_dragMode == true)
                    {
                        OnMouseDragStart?.Invoke(mx, my, button);
                    }
                }
            }
            else
            {
                m_DragStartPositionX = m_DefaultPositionXY;
                m_DragStartPositionY = m_DefaultPositionXY;

                // 마우스 드래그 엔드
                if (m_dragMode == true)
                {
                    OnMouseDragEnd?.Invoke(mx, my, button);

                    m_dragMode = false;
                }
            }
        }
示例#10
0
 private void OnMouseDown()
 {
     OnMouseClick?.Invoke(this);
 }
示例#11
0
        /// <summary>
        /// Updates the internal adminstrates and triggers events where required.
        /// </summary>
        void HandleOnStep()
        {
            //mouse can enter/leave target without moving (the target may move!)
            bool isOnTarget = _target.collider.Enabled && _target.HitTestPoint(MyGame.WorldMousePosition.x, MyGame.WorldMousePosition.y);

            if (isOnTarget && !_wasOnTarget)
            {
                OnMouseOverTarget?.Invoke(_target, MouseEventType.MouseOverTarget);
            }
            else if (!isOnTarget && _wasOnTarget)
            {
                OnMouseOffTarget?.Invoke(_target, MouseEventType.MouseOffTarget);
            }

            //did we just press the mouse down?
            if (!_wasMouseDown && Input.GetMouseButton(0))
            {
                OnMouseDown?.Invoke(_target, MouseEventType.MouseDown);
                if (isOnTarget)
                {
                    OnMouseDownOnTarget?.Invoke(_target, MouseEventType.MouseDownOnTarget);
                }
                _wasMouseDown         = true;
                _wasMouseDownOnTarget = isOnTarget;

                _offset   = _target.TransformPoint(0, 0);
                _offset.x = _offset.x - Input.mouseX;
                _offset.y = _offset.y - Input.mouseY;
            }
            else if (_wasMouseDown && !Input.GetMouseButton(0))
            {
                OnMouseUp?.Invoke(_target, MouseEventType.MouseUp);
                if (isOnTarget)
                {
                    OnMouseUpOnTarget?.Invoke(_target, MouseEventType.MouseUpOnTarget);
                }
                if (isOnTarget && _wasMouseDownOnTarget)
                {
                    OnMouseClick?.Invoke(_target, MouseEventType.MouseClick);
                }

                _wasMouseDown         = false;
                _wasMouseDownOnTarget = false;
                _offset.x             = _offset.y = 0;
            }

            if (_lastX != Input.mouseX || _lastY != Input.mouseY)
            {
                _lastX = Input.mouseX;
                _lastY = Input.mouseY;
                if (OnMouseMove != null)
                {
                    OnMouseMove(_target, MouseEventType.MouseMove);
                }
                if (isOnTarget)
                {
                    OnMouseMoveOnTarget?.Invoke(_target, MouseEventType.MouseMoveOnTarget);
                }
            }

            _wasOnTarget = isOnTarget;
        }
示例#12
0
 public void InvokeMouseClick(MouseButtonEventArgs e)
 {
     OnMouseClick?.Invoke(e);
 }
示例#13
0
 public void ClickButton()
 {
     OnMouseClick?.Invoke();
 }
示例#14
0
 private void PictureBox1_MouseClick(object sender, MouseEventArgs e)
 {
     OnMouseClick?.Invoke(this, e);
 }
示例#15
0
 internal static void HandleMouseClick(MouseEventArgs args)
 {
     OnMouseClick?.Invoke(null, new MouseArgs(args));
     mouseDown = true;
 }
示例#16
0
    // Update is called once per frame
    void Update()
    {
        Camera cam = Camera.main;

        if (cam == null)
        {
            return;
        }

        // Addon feature: change camera angle to top-down by holding space
        Vector3 rot = new Vector3(Input.GetKey(KeyCode.Space) ? 90f : cameraAngle, cam.transform.eulerAngles.y, 0f);

        cam.transform.eulerAngles = rot;

        // Mouse movement or cursor keys pan the camera in XZ
        float panX    = 0f;
        float panZ    = 0f;
        bool  panMode = false;

        if (Input.GetMouseButton(1) && !Input.GetMouseButton(0)) // right button
        {
            panMode          = true;
            Cursor.lockState = CursorLockMode.Locked;

            panX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;
            panZ = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime;

            if (invertMouse)
            {
                panX = -panX;
                panZ = -panZ;
            }
        }
        else
        {
            panX    = Input.GetAxis("Horizontal") * keyPanSpeed * Time.deltaTime;
            panZ    = Input.GetAxis("Vertical") * keyPanSpeed * Time.deltaTime;
            panMode = panX != 0f || panZ != 0f;
        }
        if (panMode)
        {
            // apply relative to camera left/right but absolute forward/back, assume cam is not rolled
            Vector3 right   = cam.transform.right;
            Vector3 forward = new Vector3(-right.z, 0f, right.x);
            groundpos += right * panX + forward * panZ;

            // groundpos.y always 0 (or maybe get the height of center tile later), x, z inside map border
            groundpos.x = Mathf.Clamp(groundpos.x, SceneMinX, SceneMaxX);
            groundpos.y = 0f;
            groundpos.z = Mathf.Clamp(groundpos.z, SceneMinZ, SceneMaxZ);
        }
        // Camera rotation around Y only
        if (Input.GetMouseButton(0) && Input.GetMouseButton(1)) // both buttons
        {
            Cursor.lockState = CursorLockMode.Locked;

            float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;

            if (invertMouse)
            {
                mouseX = -mouseX;
            }

            rot.y -= mouseX;
            cam.transform.eulerAngles = rot;
        }
        else if (!Input.GetMouseButton(0) && !Input.GetMouseButton(1))
        {
            Cursor.lockState = CursorLockMode.None;

            Ray ray = cam.ScreenPointToRay(Input.mousePosition);
            OnMouseOver?.Invoke(this.gameObject, new CameraRayEventArgs(ray));
        }

        // Apply the ground position
        cam.transform.position = groundpos;

        // Mouse wheel zoom in/out by changing camera position
        // using translate so that rotation is considered and the ground pos focused
        float mouseWheel = Input.GetAxis("Mouse ScrollWheel") * mouseWheelSensitivity * Time.deltaTime;

        if (invertWheel)
        {
            mouseWheel = -mouseWheel;
        }
        zoomDistance = Mathf.Clamp(zoomDistance - mouseWheel, zoomDistanceMin, zoomDistanceMax);
        cam.transform.Translate(0f, 0f, -zoomDistance);
        if (postProcessLayer != null)
        {
            // see https://answers.unity.com/questions/1692992/how-to-change-depth-of-field-focal-length-from-a-s.html
            List <PostProcessVolume> volList = new List <PostProcessVolume>();
            PostProcessManager.instance.GetActiveVolumes(postProcessLayer, volList, true, true);
            foreach (PostProcessVolume vol in volList)
            {
                PostProcessProfile ppp = vol.profile;
                if (ppp)
                {
                    DepthOfField dof;
                    if (ppp.TryGetSettings <DepthOfField>(out dof))
                    {
                        dof.focusDistance.value = zoomDistance;
                        dof.focalLength.value   = zoomDistance;
                    }
                }
            }
        }

        // If mouse over UI, disable selection and highlight effects, and don't allow left click
        if (EventSystem.current.IsPointerOverGameObject())
        {
            // Create a ray facing away from screen, should hit nothing, simulation click/hover into void
            Ray ray = new Ray(transform.position, -transform.forward);
            OnMouseOver?.Invoke(this.gameObject, new CameraRayEventArgs(ray));
            OnMouseClick?.Invoke(this.gameObject, new CameraRayEventArgs(ray));
        }
        // Left click with mouse selects a tile
        else if (Input.GetMouseButtonDown(0) && !Input.GetMouseButton(1)) // left button
        {
            // Cast a ray and let the GameManager decide what to do with that
            Ray ray = cam.ScreenPointToRay(Input.mousePosition);

            // To test the ray better change GetMouseButtonDown() to Input.GetMouseButton()
            // Debug.DrawRay(ray.origin, ray.direction * 300, Color.red);

            OnMouseClick?.Invoke(this.gameObject, new CameraRayEventArgs(ray));
        }
    }
示例#17
0
 public static void InvokeMouseResponse()
 {
     OnMouseClick?.Invoke();
 }
        /// <summary>
        /// Update cursor and keyboard events
        /// </summary>
        private void UpdateCursorAndKeyboardEvents()
        {
            if (!Visible)
            {
                return;
            }

            MouseEvent    mouseState = MouseHandler.GetState();
            KeyboardState kbState    = KeyboardHandler.GetState();
            var           mouseSize  = new Vector2(5);

            var mouseRect = new Rectangle((int)mouseState.X, (int)mouseState.Y, (int)mouseSize.X, (int)mouseSize.Y);

            var thisRect = new Rectangle((int)Position.X, (int)Position.Y, (int)Size.X, (int)Size.Y);

            //First check position
            if (mouseRect.Intersects(thisRect))
            {
                //Second, check buttons

                //Left
                if (LastMouseCheck.LeftButton == ButtonState.Released && mouseState.LeftButton == ButtonState.Pressed)
                {
                    OnMouseDown?.Invoke(this, mouseState.Position, MouseButtons.Left);
                }

                if (LastMouseCheck.LeftButton == ButtonState.Pressed && mouseState.LeftButton == ButtonState.Released)
                {
                    OnMouseUp?.Invoke(this, mouseState.Position, MouseButtons.Left);
                    OnMouseClick?.Invoke(this, mouseState.Position, MouseButtons.Left);
                }

                //Right
                if (LastMouseCheck.RightButton == ButtonState.Released && mouseState.RightButton == ButtonState.Pressed)
                {
                    OnMouseDown?.Invoke(this, mouseState.Position, MouseButtons.Right);
                }

                if (LastMouseCheck.RightButton == ButtonState.Pressed && mouseState.RightButton == ButtonState.Released)
                {
                    OnMouseUp?.Invoke(this, mouseState.Position, MouseButtons.Right);
                    OnMouseClick?.Invoke(this, mouseState.Position, MouseButtons.Right);
                }

                //Middle
                if (LastMouseCheck.MiddleButton == ButtonState.Released && mouseState.MiddleButton == ButtonState.Pressed)
                {
                    OnMouseDown?.Invoke(this, mouseState.Position, MouseButtons.Middle);
                }

                if (LastMouseCheck.MiddleButton == ButtonState.Pressed && mouseState.MiddleButton == ButtonState.Released)
                {
                    OnMouseUp?.Invoke(this, mouseState.Position, MouseButtons.Middle);
                    OnMouseClick?.Invoke(this, mouseState.Position, MouseButtons.Middle);
                }

                //Check move

                if (LastMouseCheck.Position != mouseState.Position)
                {
                    OnMouseMove?.Invoke(this, mouseState.Position, MouseButtons.None);
                }

                //Hook Keyboard

                if (kbState.GetPressedKeys().Count() > 0 && LastKeyboardState.GetPressedKeys().Count() > 0)
                {
                    //check pressed keys
                    List <Keys> pressedKeys = kbState.GetPressedKeys().Except(LastKeyboardState.GetPressedKeys()).ToList();

                    foreach (Keys p in pressedKeys)
                    {
                        OnKeyPress?.Invoke(this, p, kbState);
                    }

                    //check released keys
                    List <Keys> releasedKeys = LastKeyboardState.GetPressedKeys().Except(kbState.GetPressedKeys()).ToList();

                    foreach (Keys r in releasedKeys)
                    {
                        OnKeyUp?.Invoke(this, r, kbState);
                        OnKeyPress?.Invoke(this, r, kbState);
                    }
                }
            }
            else
            {
                // Leave == Release

                //Left
            }

            LastMouseCheck    = mouseState;
            LastKeyboardState = kbState;
        }
示例#19
0
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     // todo - do we need to check for null?
     OnMouseClick?.Invoke(this, e);
 }