示例#1
0
        protected override void Awake()
        {
            base.Awake();

            /// TODO TB: We don't have proper mouse pointer Ids atm, use 0 for single mouse state.
            mouseState = new MouseModel(eventSystem, 0);
            joystickState.Reset();
        }
示例#2
0
        /// <summary>
        /// Takes an existing MouseModel and dispatches all relevant changes through the event system.
        /// It also updates the internal data of the MouseModel.
        /// </summary>
        /// <param name="mouseState">The mouse state you want to forward into the UI Event System</param>
        internal void ProcessMouse(ref MouseModel mouseState)
        {
            if (!mouseState.changedThisFrame)
            {
                return;
            }

            var eventData = GetOrCreateCachedPointerEvent();

            eventData.Reset();

            mouseState.CopyTo(eventData);

            eventData.pointerCurrentRaycast = PerformRaycast(eventData);

            /// Left Mouse Button
            // The left mouse button is 'dominant' and we want to also process hover and scroll events as if the occurred during the left click.
            var buttonState = mouseState.leftButton;

            buttonState.CopyTo(eventData);
            ProcessMouseButton(buttonState.lastFrameDelta, eventData);

            ProcessMouseMovement(eventData);
            ProcessMouseScroll(eventData);

            mouseState.CopyFrom(eventData);

            ProcessMouseButtonDrag(eventData);

            buttonState.CopyFrom(eventData);
            mouseState.leftButton = buttonState;

            /// Right Mouse Button
            buttonState = mouseState.rightButton;
            buttonState.CopyTo(eventData);

            ProcessMouseButton(buttonState.lastFrameDelta, eventData);
            ProcessMouseButtonDrag(eventData);

            buttonState.CopyFrom(eventData);
            mouseState.rightButton = buttonState;

            /// Middle Mouse Button
            buttonState = mouseState.middleButton;
            buttonState.CopyTo(eventData);

            ProcessMouseButton(buttonState.lastFrameDelta, eventData);
            ProcessMouseButtonDrag(eventData);

            buttonState.CopyFrom(eventData);
            mouseState.middleButton = buttonState;

            mouseState.OnFrameFinished();
        }
示例#3
0
        /// <summary>
        /// Takes an existing MouseModel and dispatches all relevant changes through the event system.
        /// It also updates the internal data of the MouseModel.
        /// </summary>
        /// <param name="mouseState">The mouse state you want to forward into the UI Event System</param>
        internal void ProcessMouse(ref MouseModel mouseState)
        {
            if (!mouseState.changedThisFrame)
            {
                return;
            }

            var eventData = PreparePointerEventData(mouseState);

            /// Left Mouse Button
            // The left mouse button is 'dominant' and we want to also process hover and scroll events as if the occurred during the left click.
            var buttonState = mouseState.leftButton;

            buttonState.CopyTo(eventData);
            ProcessMouseButton(buttonState.lastFrameDelta, eventData);

            ProcessMouseMovement(eventData);
            ProcessMouseScroll(eventData);

            var internalMouseData = mouseState.internalData;

            internalMouseData.hoverTargets.ClearWithCapacity();
            internalMouseData.hoverTargets.Append(eventData.hovered);
            internalMouseData.pointerTarget = eventData.pointerEnter;
            mouseState.internalData         = internalMouseData;

            ProcessMouseButtonDrag(eventData);

            buttonState.CopyFrom(eventData);
            mouseState.leftButton = buttonState;

            /// Right Mouse Button
            buttonState = mouseState.rightButton;
            buttonState.CopyTo(eventData);

            ProcessMouseButton(buttonState.lastFrameDelta, eventData);
            ProcessMouseButtonDrag(eventData);

            buttonState.CopyFrom(eventData);
            mouseState.rightButton = buttonState;

            /// Middle Mouse Button
            buttonState = mouseState.middleButton;
            buttonState.CopyTo(eventData);

            ProcessMouseButton(buttonState.lastFrameDelta, eventData);
            ProcessMouseButtonDrag(eventData);

            buttonState.CopyFrom(eventData);
            mouseState.middleButton = buttonState;

            mouseState.OnFrameFinished();
        }
        protected override void Awake()
        {
            base.Awake();

            m_RollingPointerId = 0;
            mouseState         = new MouseModel(m_RollingPointerId++);
            joystickState.Reset();

            if (m_Touches == null)
            {
                m_Touches = new List <TouchResponder>();
            }

            for (int i = 0; i < m_Touches.Count; i++)
            {
                var responder = m_Touches[i];
                responder.state = new TouchModel(m_RollingPointerId++);

                var newIndex = i;
                responder.actionCallback = delegate(InputAction.CallbackContext context)
                {
                    OnTouchAction(newIndex, context);
                };
                m_Touches[i] = responder;
            }

            if (m_TrackedDevices == null)
            {
                m_TrackedDevices = new List <TrackedDeviceResponder>();
            }

            for (int i = 0; i < m_TrackedDevices.Count; i++)
            {
                var responder = m_TrackedDevices[i];
                responder.state = new TrackedDeviceModel(m_RollingPointerId++);

                var newIndex = i;
                responder.actionCallback = delegate(InputAction.CallbackContext context)
                {
                    OnTrackedDeviceAction(newIndex, context);
                };
                m_TrackedDevices[i] = responder;
            }
        }
示例#5
0
        private PointerEventData PreparePointerEventData(MouseModel mouseState)
        {
            var eventData = GetOrCreateCachedPointerEvent();

            eventData.Reset();

            eventData.pointerId    = mouseState.pointerId;
            eventData.position     = mouseState.position;
            eventData.delta        = mouseState.deltaPosition;
            eventData.scrollDelta  = mouseState.scrollDelta;
            eventData.pointerEnter = mouseState.internalData.pointerTarget;

            eventData.hovered.Clear();
            eventData.hovered.AddRange(mouseState.internalData.hoverTargets);

            // This is unset in legacy systems and can safely assumed to stay true.
            eventData.useDragThreshold = true;

            eventData.pointerCurrentRaycast = PerformRaycast(eventData);

            return(eventData);
        }