Exemplo n.º 1
0
            public static bool Prefix(bool useKeyboard, bool useController, GameInput ___instance)
            {
                XRInputManager xrInput = GetXRInputManager();

                if (!xrInput.hasControllers())
                {
                    return(true);
                }

                for (int i = 0; i < GameInput.axisValues.Length; i++)
                {
                    GameInput.axisValues[i] = 0f;
                }
                if (useController)
                {
                    Vector2 vector = xrInput.Get(Controller.Left, CommonUsages.primary2DAxis);
                    GameInput.axisValues[2] = vector.x;
                    GameInput.axisValues[3] = -vector.y;
                    Vector2 vector2 = xrInput.Get(Controller.Right, CommonUsages.primary2DAxis);
                    GameInput.axisValues[0] = vector2.x;
                    GameInput.axisValues[1] = -vector2.y;
                    // TODO: Use deadzone?
                    GameInput.axisValues[4] = xrInput.Get(Controller.Left, CommonUsages.trigger).CompareTo(0.3f);
                    GameInput.axisValues[5] = xrInput.Get(Controller.Right, CommonUsages.trigger).CompareTo(0.3f);
                }
                if (useKeyboard)
                {
                    GameInput.axisValues[10] = Input.GetAxis("Mouse ScrollWheel");
                    GameInput.axisValues[8]  = Input.GetAxisRaw("Mouse X");
                    GameInput.axisValues[9]  = Input.GetAxisRaw("Mouse Y");
                }
                for (int j = 0; j < GameInput.axisValues.Length; j++)
                {
                    GameInput.AnalogAxis axis          = (GameInput.AnalogAxis)j;
                    GameInput.Device     deviceForAxis = ___instance.GetDeviceForAxis(axis);
                    float f = GameInput.lastAxisValues[j] - GameInput.axisValues[j];
                    GameInput.lastAxisValues[j] = GameInput.axisValues[j];
                    if (deviceForAxis != GameInput.lastDevice)
                    {
                        float num = 0.1f;
                        if (Mathf.Abs(f) > num)
                        {
                            if (!PlatformUtils.isConsolePlatform)
                            {
                                GameInput.lastDevice = deviceForAxis;
                            }
                        }
                        else
                        {
                            GameInput.axisValues[j] = 0f;
                        }
                    }
                }
                return(false);
            }
Exemplo n.º 2
0
            public static bool Prefix(bool useKeyboard, bool useController)
            {
                XRInputManager xrInput = GetXRInputManager();

                if (!xrInput.hasControllers())
                {
                    return(true);
                }

                float unscaledTime = Time.unscaledTime;

                for (int i = 0; i < GameInput.inputs.Count; i++)
                {
                    GameInput.InputState inputState     = default;
                    GameInput.InputState prevInputState = GameInput.inputStates[i];
                    inputState.timeDown = prevInputState.timeDown;
                    bool wasHeld = (prevInputState.flags & GameInput.InputStateFlags.Held) > 0U;

                    GameInput.Input  currentInput = GameInput.inputs[i];
                    GameInput.Device device       = currentInput.device;
                    KeyCode          key          = currentInput.keyCode;

                    if (key != KeyCode.None)
                    {
                        bool pressed = xrInput.GetXRInput(key);
                        GameInput.InputStateFlags prevState = GameInput.inputStates[i].flags;
                        if (pressed && (prevState == GameInput.InputStateFlags.Held && prevState == GameInput.InputStateFlags.Down))
                        {
                            inputState.flags |= GameInput.InputStateFlags.Held;
                        }
                        if (pressed && prevState == GameInput.InputStateFlags.Up)
                        {
                            inputState.flags |= GameInput.InputStateFlags.Down;
                        }
                        if (!pressed)
                        {
                            inputState.flags |= GameInput.InputStateFlags.Up;
                        }
                        if (inputState.flags != 0U && !PlatformUtils.isConsolePlatform && (GameInput.controllerEnabled || device != GameInput.Device.Controller))
                        {
                            GameInput.lastDevice = device;
                        }
                    }
                    else
                    {
                        float axisValue = GameInput.axisValues[(int)currentInput.axis];
                        bool  isPressed;
                        if (GameInput.inputs[i].axisPositive)
                        {
                            isPressed = (axisValue > currentInput.axisDeadZone);
                        }
                        else
                        {
                            isPressed = (axisValue < -currentInput.axisDeadZone);
                        }
                        if (isPressed)
                        {
                            inputState.flags |= GameInput.InputStateFlags.Held;
                        }
                        if (isPressed && !wasHeld)
                        {
                            inputState.flags |= GameInput.InputStateFlags.Down;
                        }
                        if (!isPressed && wasHeld)
                        {
                            inputState.flags |= GameInput.InputStateFlags.Up;
                        }
                    }

                    if ((inputState.flags & GameInput.InputStateFlags.Down) != 0U)
                    {
                        int lastIndex = GameInput.lastInputPressed[(int)device];
                        int newIndex  = i;
                        inputState.timeDown = unscaledTime;
                        if (lastIndex > -1)
                        {
                            GameInput.Input lastInput         = GameInput.inputs[lastIndex];
                            bool            isSameTime        = inputState.timeDown == GameInput.inputStates[lastIndex].timeDown;
                            bool            lastAxisIsGreater = Mathf.Abs(GameInput.axisValues[(int)lastInput.axis]) > Mathf.Abs(GameInput.axisValues[(int)currentInput.axis]);
                            if (isSameTime && lastAxisIsGreater)
                            {
                                newIndex = lastIndex;
                            }
                        }
                        GameInput.lastInputPressed[(int)device] = newIndex;
                    }

                    if ((device == GameInput.Device.Controller && !useController) || (device == GameInput.Device.Keyboard && !useKeyboard))
                    {
                        inputState.flags = 0U;
                        if (wasHeld)
                        {
                            inputState.flags |= GameInput.InputStateFlags.Up;
                        }
                    }
                    GameInput.inputStates[i] = inputState;
                }

                return(false);
            }