コード例 #1
0
        protected MouseState InputToPointerEvent(CursorInput input)
        {
            if (_leftData == null)
            {
                _leftData = new RayPointerEventData(eventSystem);
            }

            // Populate the left button...
            _leftData.Reset();

            //_leftData.delta = input.MovementDelta;
            _leftData.delta       = Vector2.zero;
            _leftData.scrollDelta = input.ScrollDelta;
            _leftData.button      = PointerEventData.InputButton.Left;
            _leftData.Ray         = input.Ray;
            eventSystem.RaycastAll(_leftData, m_RaycastResultCache);
            var raycast = FindFirstRaycast(m_RaycastResultCache);

            if (raycast.gameObject != null)
            {
                //Debug.Log("first raycast " + raycast.gameObject.name, raycast.gameObject);
                //Debug.Log("hit objects: " + string.Join(", ", m_RaycastResultCache.Select(r => r.gameObject.name).ToArray()));
            }
            _leftData.pointerCurrentRaycast = raycast;
            m_RaycastResultCache.Clear();

//            var raycaster = raycast.module as RayBasedRaycaster;
//            if (raycaster != null) {
//                _leftData.position = raycaster.GetScreenPos(raycast.worldPosition);
//            } else {
//                _leftData.position = input.ScreenPosition;
//            }
            _leftData.position = input.ScreenPosition;

            // copy the apropriate data into right and middle slots
//            PointerEventData rightData;
//            GetPointerData(kMouseRightId, out rightData, true);
//            CopyFromTo(_leftData, rightData);
//            rightData.button = PointerEventData.InputButton.Right;
//
//            PointerEventData middleData;
//            GetPointerData(kMouseMiddleId, out middleData, true);
//            CopyFromTo(_leftData, middleData);
//            middleData.button = PointerEventData.InputButton.Middle;

            _mouseState.SetButtonState(PointerEventData.InputButton.Left, input.SubmitEvent, _leftData);
//            _mouseState.SetButtonState(PointerEventData.InputButton.Right, PointerEventData.FramePressState.NotChanged, rightData);
//            _mouseState.SetButtonState(PointerEventData.InputButton.Middle, PointerEventData.FramePressState.NotChanged, middleData);
            return(_mouseState);
        }
コード例 #2
0
        public void Process(CursorInput cursorInput, NavigationInput navInput)
        {
            bool usedEvent = SendUpdateEventToSelectedObject();

            if (eventSystem.sendNavigationEvents)
            {
                if (!usedEvent)
                {
                    usedEvent |= SendMoveEventToSelectedObject(navInput);
                }

                if (!usedEvent)
                {
                    SendSubmitEventToSelectedObject(navInput);
                }
            }

            ProcessMouseEvent(cursorInput);
        }
コード例 #3
0
        /// <summary>
        /// Process all mouse events.
        /// </summary>
        protected void ProcessMouseEvent(CursorInput input)
        {
            var mouseData      = InputToPointerEvent(input);
            var leftButtonData = mouseData.GetButtonState(PointerEventData.InputButton.Left).eventData;

            // Process the first mouse button fully
            ProcessMousePress(leftButtonData);
            ProcessMove(leftButtonData.buttonData);
            ProcessDrag(leftButtonData.buttonData);

            // Now process right / middle clicks
//            ProcessMousePress(mouseData.GetButtonState(PointerEventData.InputButton.Right).eventData);
//            ProcessDrag(mouseData.GetButtonState(PointerEventData.InputButton.Right).eventData.buttonData);
//            ProcessMousePress(mouseData.GetButtonState(PointerEventData.InputButton.Middle).eventData);
//            ProcessDrag(mouseData.GetButtonState(PointerEventData.InputButton.Middle).eventData.buttonData);

            if (!Mathf.Approximately(leftButtonData.buttonData.scrollDelta.sqrMagnitude, 0.0f))
            {
                var scrollHandler = ExecuteEvents.GetEventHandler <IScrollHandler>(leftButtonData.buttonData.pointerCurrentRaycast.gameObject);
                ExecuteEvents.ExecuteHierarchy(scrollHandler, leftButtonData.buttonData, ExecuteEvents.scrollHandler);
            }
        }