Пример #1
0
        private bool ShouldSendMoveFromInput()
        {
            float time = Time.unscaledTime;

            Vector2 movement = GetRawMoveVector();

            if (Mathf.Approximately(movement.x, 0f) && Mathf.Approximately(movement.y, 0f))
            {
                m_ConsecutiveMoveCount = 0;
                return(false);
            }

            // If user pressed key again, always allow event
            bool allow      = input.GetButtonDown(m_HorizontalAxis) || input.GetButtonDown(m_VerticalAxis);
            bool similarDir = (Vector2.Dot(movement, m_LastMoveVector) > 0);

            if (!allow)
            {
                // Otherwise, user held down key or axis.
                // If direction didn't change at least 90 degrees, wait for delay before allowing consecutive event.
                if (similarDir && m_ConsecutiveMoveCount == 1)
                {
                    allow = (time > m_PrevActionTime + m_RepeatDelay);
                }
                // If direction changed at least 90 degree, or we already had the delay, repeat at repeat rate.
                else
                {
                    allow = (time > m_PrevActionTime + 1f / m_InputActionsPerSecond);
                }
            }

            if (!allow)
            {
                return(false);
            }

            // Debug.Log(m_ProcessingEvent.rawType + " axis:" + m_AllowAxisEvents + " value:" + "(" + x + "," + y + ")");
            var moveDirection = NavigationMoveEvent.DetermineMoveDirection(movement.x, movement.y);

            if (moveDirection != NavigationMoveEvent.Direction.None)
            {
                if (!similarDir)
                {
                    m_ConsecutiveMoveCount = 0;
                }
                m_ConsecutiveMoveCount++;
                m_PrevActionTime = time;
                m_LastMoveVector = movement;
            }
            else
            {
                m_ConsecutiveMoveCount = 0;
            }

            return(moveDirection != NavigationMoveEvent.Direction.None);
        }
Пример #2
0
        void Update()
        {
            if (focusedPanel == null)
            {
                return;
            }

            if (focusedPanel != null && !isAppFocused && ShouldIgnoreEventsOnAppNotFocused())
            {
                return;
            }

            if (sendIMGUIEvents)
            {
                while (Event.PopEvent(m_Event))
                {
                    if (m_Event.type == EventType.Repaint)
                    {
                        continue;
                    }

                    var panelPosition = Vector2.zero;
                    var panelDelta    = Vector2.zero;

                    if (ScreenToPanel(focusedPanelRenderer, m_Event.mousePosition, m_Event.delta, out panelPosition, out panelDelta))
                    {
                        m_Event.mousePosition = panelPosition;
                        m_Event.delta         = panelDelta;

                        using (EventBase evt = InternalBridge.CreateEvent(m_Event))
                        {
                            focusedPanel.visualTree.SendEvent(evt);
                        }
                    }
                }
            }

            if (sendInputEvents)
            {
                if (sendNavigationEvents)
                {
                    bool sendNavigationMove = ShouldSendMoveFromInput();

                    if (sendNavigationMove)
                    {
                        using (EventBase evt = NavigationMoveEvent.GetPooled(GetRawMoveVector()))
                        {
                            focusedPanel.visualTree.SendEvent(evt);
                        }
                    }

                    if (input.GetButtonDown(m_SubmitButton))
                    {
                        using (EventBase evt = NavigationSubmitEvent.GetPooled())
                        {
                            focusedPanel.visualTree.SendEvent(evt);
                        }
                    }

                    if (input.GetButtonDown(m_CancelButton))
                    {
                        using (EventBase evt = NavigationCancelEvent.GetPooled())
                        {
                            focusedPanel.visualTree.SendEvent(evt);
                        }
                    }
                }

                if (!ProcessTouchEvents() && input.mousePresent)
                {
                    ProcessMouseEvents();
                }
            }
        }