Exemple #1
0
        public override bool ShouldActivateModule()
        {
            if (!base.ShouldActivateModule())
            {
                return(false);
            }
            if (recompiling)
            {
                return(false);
            }
            if (!ReInput.isReady)
            {
                return(false);
            }

            bool shouldActivate = false;

            // Combine input for all players
            for (int i = 0; i < playerIds.Length; i++)
            {
                Rewired.Player player = ReInput.players.GetPlayer(playerIds[i]);
                if (player == null)
                {
                    continue;
                }

                shouldActivate |= player.GetButtonDown(m_SubmitButton);
                shouldActivate |= player.GetButtonDown(m_CancelButton);
                if (moveOneElementPerAxisPress)  // axis press moves only to the next UI element with each press
                {
                    shouldActivate |= player.GetButtonDown(m_HorizontalAxis) || player.GetNegativeButtonDown(m_HorizontalAxis);
                    shouldActivate |= player.GetButtonDown(m_VerticalAxis) || player.GetNegativeButtonDown(m_VerticalAxis);
                }
                else     // default behavior - axis press scrolls quickly through UI elements
                {
                    shouldActivate |= !Mathf.Approximately(player.GetAxisRaw(m_HorizontalAxis), 0.0f);
                    shouldActivate |= !Mathf.Approximately(player.GetAxisRaw(m_VerticalAxis), 0.0f);
                }
            }

            if (isMouseSupported)
            {
                shouldActivate |= (m_MousePosition - m_LastMousePosition).sqrMagnitude > 0.0f;
                shouldActivate |= ReInput.controllers.Mouse.GetButtonDown(0);
            }

            return(shouldActivate);
        }
Exemple #2
0
        private bool CheckButtonOrKeyMovement(float time)
        {
            bool allow = false;

            for (int i = 0; i < playerIds.Length; i++)
            {
                Rewired.Player player = ReInput.players.GetPlayer(playerIds[i]);
                if (player == null)
                {
                    continue;
                }

                allow |= player.GetButtonDown(m_HorizontalAxis) || player.GetNegativeButtonDown(m_HorizontalAxis);
                allow |= player.GetButtonDown(m_VerticalAxis) || player.GetNegativeButtonDown(m_VerticalAxis);
            }

            return(allow);
        }
        private bool AllowMoveEventProcessing(float time)
        {
            if (recompiling)
            {
                return(false);
            }

            bool allow = false;

            for (int i = 0; i < players.Length; i++)
            {
                Rewired.Player player = players[i];
                if (player == null)
                {
                    continue;
                }

                allow |= player.GetButtonDown(m_HorizontalAxis) || player.GetNegativeButtonDown(m_HorizontalAxis);
                allow |= player.GetButtonDown(m_VerticalAxis) || player.GetNegativeButtonDown(m_VerticalAxis);
                allow |= (time > m_NextAction);
            }

            return(allow);
        }
        private Vector2 GetRawMoveVector()
        {
            if (recompiling)
            {
                return(Vector2.zero);
            }

            Vector2 move        = Vector2.zero;
            bool    horizButton = false;
            bool    vertButton  = false;

            // Combine inputs of all Players
            for (int i = 0; i < playerIds.Length; i++)
            {
                Rewired.Player player = ReInput.players.GetPlayer(playerIds[i]);
                if (player == null)
                {
                    continue;
                }
                if (usePlayingPlayersOnly && !player.isPlaying)
                {
                    continue;
                }

                if (moveOneElementPerAxisPress)  // axis press moves only to the next UI element with each press
                {
                    float x = 0.0f;
                    if (player.GetButtonDown(m_HorizontalAxis))
                    {
                        x = 1.0f;
                    }
                    else if (player.GetNegativeButtonDown(m_HorizontalAxis))
                    {
                        x = -1.0f;
                    }

                    float y = 0.0f;
                    if (player.GetButtonDown(m_VerticalAxis))
                    {
                        y = 1.0f;
                    }
                    else if (player.GetNegativeButtonDown(m_VerticalAxis))
                    {
                        y = -1.0f;
                    }

                    move.x += x;
                    move.y += y;
                }
                else     // default behavior - axis press scrolls quickly through UI elements
                {
                    move.x += player.GetAxisRaw(m_HorizontalAxis);
                    move.y += player.GetAxisRaw(m_VerticalAxis);
                }

                horizButton |= player.GetButtonDown(m_HorizontalAxis) || player.GetNegativeButtonDown(m_HorizontalAxis);
                vertButton  |= player.GetButtonDown(m_VerticalAxis) || player.GetNegativeButtonDown(m_VerticalAxis);
            }

            if (horizButton)
            {
                if (move.x < 0)
                {
                    move.x = -1f;
                }
                if (move.x > 0)
                {
                    move.x = 1f;
                }
            }
            if (vertButton)
            {
                if (move.y < 0)
                {
                    move.y = -1f;
                }
                if (move.y > 0)
                {
                    move.y = 1f;
                }
            }
            return(move);
        }
        public override bool ShouldActivateModule()
        {
            if (!base.ShouldActivateModule())
            {
                return(false);
            }
            if (recompiling)
            {
                return(false);
            }
            if (!ReInput.isReady)
            {
                return(false);
            }

            bool shouldActivate = m_ForceModuleActive;

            // Combine input for all players
            for (int i = 0; i < playerIds.Length; i++)
            {
                Rewired.Player player = ReInput.players.GetPlayer(playerIds[i]);
                if (player == null)
                {
                    continue;
                }
                if (usePlayingPlayersOnly && !player.isPlaying)
                {
                    continue;
                }

                shouldActivate |= player.GetButtonDown(m_SubmitButton);
                shouldActivate |= player.GetButtonDown(m_CancelButton);
                if (moveOneElementPerAxisPress)  // axis press moves only to the next UI element with each press
                {
                    shouldActivate |= player.GetButtonDown(m_HorizontalAxis) || player.GetNegativeButtonDown(m_HorizontalAxis);
                    shouldActivate |= player.GetButtonDown(m_VerticalAxis) || player.GetNegativeButtonDown(m_VerticalAxis);
                }
                else     // default behavior - axis press scrolls quickly through UI elements
                {
                    shouldActivate |= !Mathf.Approximately(player.GetAxisRaw(m_HorizontalAxis), 0.0f);
                    shouldActivate |= !Mathf.Approximately(player.GetAxisRaw(m_VerticalAxis), 0.0f);
                }
            }

            // Mouse input
            if (isMouseSupported)
            {
                shouldActivate |= (m_MousePosition - m_LastMousePosition).sqrMagnitude > 0.0f;
                shouldActivate |= UnityEngine.Input.GetMouseButtonDown(0);
            }

            // Touch input
            if (isTouchSupported)
            {
                for (int i = 0; i < Input.touchCount; ++i)
                {
                    Touch input = Input.GetTouch(i);
                    shouldActivate |= input.phase == TouchPhase.Began ||
                                      input.phase == TouchPhase.Moved ||
                                      input.phase == TouchPhase.Stationary;
                }
            }

            return(shouldActivate);
        }