Exemplo n.º 1
0
        protected void OnActionFirst(InputAction.CallbackContext context)
        {
            var control = context.control;
            var device  = control.device;

            var isMouseInput = device is Mouse;

            // Read our current pointer values.
            var drag = context.ReadValue <PointerInput>();

            if (isMouseInput)
            {
                drag.InputId = Helpers.LeftMouseInputId;
            }

            if (drag.Contact && !m_DraggingFirst)
            {
                PressedFirst?.Invoke(drag, context.time);
                m_DraggingFirst = true;
            }
            else if (drag.Contact && m_DraggingFirst)
            {
                DraggedFirst?.Invoke(drag, context.time);
            }
            else
            {
                ReleasedFirst?.Invoke(drag, context.time);
                m_DraggingFirst = false;
            }
        }
        private void OnPressedFirst(PointerInput input, double time)
        {
            Debug.Assert(!activeGestures.ContainsKey(input.InputId));

            var newGesture = new ActiveGesture(input.InputId, input.Position, time);

            activeGestures.Add(input.InputId, newGesture);

            DebugInfo(newGesture);

            _posLastFirst = input.Position;

            if (_secondPressed)
            {
                _pinching = true;

                _pinchPosStartFirst  = _posLastFirst;
                _pinchPosStartSecond = _posLastSecond;

                _pinchStartDistance = Vector2.Distance(_pinchPosStartFirst, _pinchPosStartSecond);
                _pinchLastDistance  = _pinchStartDistance;

                PinchStarted?.Invoke(new PinchInput()
                {
                    InputId                 = input.InputId,
                    PinchDeltaDistance      = 0,
                    PinchDistance           = _pinchStartDistance,
                    Pointer0CurrentPosition = _pinchPosStartFirst,
                    Pointer0StartPosition   = _pinchPosStartFirst,
                    Pointer1CurrentPosition = _pinchPosStartSecond,
                    Pointer1StartPosition   = _pinchPosStartSecond
                });
            }

            PressedFirst?.Invoke(new SwipeInput(newGesture));
        }