Пример #1
0
 private void Awake()
 {
     an         = GetComponent <Animator>();
     rb         = GetComponent <Rigidbody2D>();
     sr         = GetComponent <SpriteRenderer>();
     controller = GetComponent <ControllerInputs>();
 }
Пример #2
0
        /// <summary>
        /// Your own user code starts here.
        /// If this is your first time, do consider reading the notice above.
        /// It contains some very useful information.
        /// </summary>
        public static void Init()
        {
            /*
             *  Reloaded Mod Loader Sample: Reloaded Input Stack Demo
             *  Architectures supported: X86, X64
             *
             *  Demonstrates how to use the Reloaded Input Stack to read user inputs.
             */

            // Want to see this in with a debugger? Uncomment this line.
            // Debugger.Launch();

            // Print demo details.
            Thread controllerReadThread = new Thread(() =>
            {
                // The main hub/interface for directing with controllers.
                ControllerManager controllerManager = new ControllerManager();
                int controllerPort = 0;             // Arrays start at X

                // Get inputs and print them.
                while (true)
                {
                    // That's it, did you expect anything more? Easy peasy!
                    ControllerInputs inputs = controllerManager.GetInput(controllerPort);

                    // Let's print it to the console.
                    Bindings.PrintText
                    (
                        "///////////////////////CONTROLLER INPUT BEGIN\n" +
                        $"Buttons (Some of them):\n" +
                        $"A: {inputs.ControllerButtons.ButtonA}\n" +
                        $"B: {inputs.ControllerButtons.ButtonB}\n" +
                        $"X: {inputs.ControllerButtons.ButtonX}\n" +
                        $"Y: {inputs.ControllerButtons.ButtonY}\n" +
                        $"LB: {inputs.ControllerButtons.ButtonLb}\n" +
                        $"RB: {inputs.ControllerButtons.ButtonRb}\n" +
                        $"Axis (Some of them):\n" +
                        $"Left Stick X: {inputs.LeftStick.GetX()}\n" +
                        $"Left Stick Y: {inputs.LeftStick.GetY()}\n" +
                        $"Left Trigger: {inputs.GetLeftTriggerPressure()}\n" +
                        $"Right Trigger: {inputs.GetRightTriggerPressure()}\n" +
                        $"Game Window Has Focus: {Reloaded.Native.Functions.WindowProperties.IsWindowActivated(GameProcess.Process.MainWindowHandle)}\n" +
                        "///////////////////////CONTROLLER INPUT END\n"
                    );

                    // Refresh approximately every 1/3 second.
                    Thread.Sleep(333);
                }

                /*
                 *  The controller code is all custom and written from the ground up over SharpDX.
                 *  Automatic Hotplugging, Remapping, Deadzones, Button to Axis, Axis to Axis etc. are supported.
                 *  Feel free to poke around the libReloaded library.
                 */
            });

            controllerReadThread.Start();
        }
Пример #3
0
    public bool GetKey(ControllerKeyCode keyCode)
    {
        if (keyCode <= ControllerKeyCode.RightStick)
        {
            return(ControllerInputs.GetControllerValue((int)keyCode, ControllerInputs.ButtonState.Held));
        }

        return(false);
    }
Пример #4
0
 private void Awake()
 {
     m_Rigidbody2D = GetComponent <Rigidbody2D>();
     animator      = GetComponent <Animator>();
     controller    = new ControllerInputs(this);
     physicsBox    = GetComponent <BoxCollider2D>();
     layer         = gameObject.layer;
     SetState(new AirState(this));
 }
Пример #5
0
    public void OnTriggerEnter(Collider col)
    {
        if (col.gameObject.tag == "VRController")
        {
            //Set button
            ControllerInputs inputObject = GameObject.FindGameObjectWithTag("InputController").GetComponent <ControllerInputs>();
            inputObject.CollidedObject = this.gameObject;

            controller = col.transform.parent.gameObject.GetComponent <ControllerHolder>();
        }
    }
Пример #6
0
    public void OnTriggerExit(Collider col)
    {
        if (col.gameObject.tag == "VRController")
        {
            //Unset button
            ControllerInputs inputObject = GameObject.FindGameObjectWithTag("InputController").GetComponent <ControllerInputs>();
            inputObject.CollidedObject = null;

            //controller = null;
        }
    }
Пример #7
0
    void OnTriggerExit(Collider col)
    {
        if (col.gameObject.tag == "VRController")
        {
            //Set button
            ControllerInputs inputObject = GameObject.FindGameObjectWithTag("InputController").GetComponent <ControllerInputs>();
            inputObject.CollidedButton = null;

            //Highlight this button
            EventSystem.current.SetSelectedGameObject(null);
        }
    }
Пример #8
0
    void OnTriggerEnter(Collider col)
    {
        if (col.gameObject.tag == "VRController")
        {
            //Set button
            ControllerInputs inputObject = GameObject.FindGameObjectWithTag("InputController").GetComponent <ControllerInputs>();
            inputObject.CollidedButton = thisButton;

            //Highlight this button
            thisButton.Select();
        }
    }
Пример #9
0
 // Start is called before the first frame update
 void Start()
 {
     plane                = transform;
     engineController     = gameObject.GetComponent <EngineController>();
     flightDataVisualizer = gameObject.GetComponentInChildren <FlightDataVisualizer>();
     controllerInputs     = GameObject.Find("VRActions").GetComponent <ControllerInputs>();
     pathNavigator        = this.GetComponent <PathNavigator>();
     navigationComputer   = this.GetComponent <NavigationComputer>();
     currentFlightData    = new FlightData(plane, engineController, pathNavigator);
     flightDataVisualizer.CurrentFlightData = currentFlightData;
     soundController = GetComponentInChildren <SoundController>();
     soundController.FlightComputerRef = this;
 }
Пример #10
0
            /// <summary>
            /// Finds and executes the highest priority action associated with the given input.
            /// </summary>
            /// <param name="input">The input to be executed.</param>
            private void RunAction(ControllerInputs input)
            {
                OverworldObjectAction action = currentOverworldObject.GetOverworldObjectAction(input);

                if (action != null)
                {
                    action.ExecuteAction();
                }
                else
                {
                    Debug.Log("no owoaction on input " + input.ToString());
                }
            }
Пример #11
0
 /// <summary>
 /// Processes the obtained controller inputs from a background thread.
 /// </summary>
 /// <param name="controllerInputs"></param>
 private void ProcessInputs(ControllerInputs controllerInputs)
 {
     if (controllerInputs.ControllerButtons.ButtonLs)
     {
         if (!_ignoringWindow)
         {
             _overlayHelper.IgnoreWindow();
         }
         else
         {
             _overlayHelper.UnIgnoreWindow();
         }
         _ignoringWindow = !_ignoringWindow;
     }
 }
        /// <summary>
        /// Retrieves and returns the state of all of the controller's individual buttons.
        /// </summary>
        /// <param name="controllerInputs">The controller input struct.</param>
        private ControllerInputs GetControllerStateAxis(ControllerInputs controllerInputs)
        {
            // Retrieve all of the axis.
            controllerInputs.SetLeftTriggerPressure(GetAxisState(ControllerAxis.LeftTrigger));
            controllerInputs.SetRightTriggerPressure(GetAxisState(ControllerAxis.RightTrigger));

            controllerInputs.LeftStick.SetX(GetAxisState(ControllerAxis.LeftStickX));
            controllerInputs.LeftStick.SetY(GetAxisState(ControllerAxis.LeftStickY));

            controllerInputs.RightStick.SetX(GetAxisState(ControllerAxis.RightStickX));
            controllerInputs.RightStick.SetY(GetAxisState(ControllerAxis.RightStickY));

            // Return the axis.
            return(controllerInputs);
        }
Пример #13
0
            public OverworldObjectAction GetOverworldObjectAction(ControllerInputs input)
            {
                OverworldObjectAction overworldObjectAction = null;

                foreach (OverworldObjectAction action in owoActions)
                {
                    if (action.GetControllerInput() == input &&
                        (overworldObjectAction == null || action.GetPriority() > overworldObjectAction.GetPriority()))
                    {
                        overworldObjectAction = action;
                    }
                }

                return(overworldObjectAction);
            }
Пример #14
0
        /// <summary>
        /// Retrieves the state of all of the axis and buttons of the controller as well as the DPAD state
        /// and retrieves it in a struct format convenient for the modder's use.
        /// </summary>
        /// <returns>Controller inputs as a custom struct.</returns>
        public ControllerInputs GetControllerState()
        {
            // Update the current state of the Joystick/Controller
            JoystickState = GetCurrentState();

            // Instantiate an instance of controller inputs.
            ControllerInputs controllerInputs = new ControllerInputs();

            // Retrieve all of the buttons;
            controllerInputs = GetCurrentButtons(controllerInputs);

            // Retrieve all of the axis.
            controllerInputs = GetCurrentAxis(controllerInputs);

            // Retrieve DPAD Information
            if (JoystickState.PointOfViewControllers[0] == -1)
            {
            }
            else
            {
                switch ((DpadDirection)JoystickState.PointOfViewControllers[0])
                {
                case DpadDirection.Up: controllerInputs.ControllerButtons.DpadUp = true; break;

                case DpadDirection.Down: controllerInputs.ControllerButtons.DpadDown = true; break;

                case DpadDirection.Left: controllerInputs.ControllerButtons.DpadLeft = true; break;

                case DpadDirection.Right: controllerInputs.ControllerButtons.DpadRight = true; break;

                case DpadDirection.UpLeft: controllerInputs.ControllerButtons.DpadUp = true; controllerInputs.ControllerButtons.DpadLeft = true; break;

                case DpadDirection.UpRight: controllerInputs.ControllerButtons.DpadUp = true; controllerInputs.ControllerButtons.DpadRight = true; break;

                case DpadDirection.DownLeft: controllerInputs.ControllerButtons.DpadDown = true; controllerInputs.ControllerButtons.DpadLeft = true; break;

                case DpadDirection.DownRight: controllerInputs.ControllerButtons.DpadDown = true; controllerInputs.ControllerButtons.DpadRight = true; break;
                }
            }

            // Retrieve Emulated Keys
            controllerInputs = GetCurrentEmulatedKeys(controllerInputs);

            // Return to base.
            return(controllerInputs);
        }
Пример #15
0
        /// <summary>
        /// Retrieves and returns the state of all of the controller's individual buttons.
        /// </summary>
        /// <param name="controllerInputs">The controller input struct.</param>
        private ControllerInputs GetControllerStateButtons(ControllerInputs controllerInputs)
        {
            // Retrieve all of the buttons.
            controllerInputs.ControllerButtons.ButtonA = GetButtonState(ControllerButtonsGeneric.ButtonA);
            controllerInputs.ControllerButtons.ButtonB = GetButtonState(ControllerButtonsGeneric.ButtonB);
            controllerInputs.ControllerButtons.ButtonX = GetButtonState(ControllerButtonsGeneric.ButtonX);
            controllerInputs.ControllerButtons.ButtonY = GetButtonState(ControllerButtonsGeneric.ButtonY);

            controllerInputs.ControllerButtons.ButtonLb = GetButtonState(ControllerButtonsGeneric.ButtonLb);
            controllerInputs.ControllerButtons.ButtonRb = GetButtonState(ControllerButtonsGeneric.ButtonRb);

            controllerInputs.ControllerButtons.ButtonBack  = GetButtonState(ControllerButtonsGeneric.ButtonBack);
            controllerInputs.ControllerButtons.ButtonGuide = GetButtonState(ControllerButtonsGeneric.ButtonGuide);
            controllerInputs.ControllerButtons.ButtonStart = GetButtonState(ControllerButtonsGeneric.ButtonStart);

            // Return the buttons.
            return(controllerInputs);
        }
Пример #16
0
        /// <summary>
        /// Sets the analog stick values for the individual <see cref="HeroesController"/>.
        /// </summary>
        private void SetSticks(ref ControllerInputs controllerInputs)
        {
            var   leftStick  = controllerInputs.LeftStick;
            var   rightStick = controllerInputs.RightStick;
            float maxValue   = ControllerCommon.AxisMaxValueF;

            // Get sticks.
            float leftStickX  = (*HeroesController).GetScaledAnalogValue(leftStick.GetX(), maxValue);
            float leftStickY  = (*HeroesController).GetScaledAnalogValue(leftStick.GetY(), maxValue);
            float rightStickX = (*HeroesController).GetScaledAnalogValue(rightStick.GetX(), maxValue);
            float rightStickY = (*HeroesController).GetScaledAnalogValue(rightStick.GetY(), maxValue);

            // Update struct.
            (*HeroesController).LeftStickX  = leftStickX;
            (*HeroesController).LeftStickY  = leftStickY;
            (*HeroesController).RightStickX = rightStickX;
            (*HeroesController).RightStickY = rightStickY;
        }
        /// <summary>
        /// Retrieves the state of all of the axis and buttons of the controller as well as the DPAD state
        /// and retrieves it in a struct format convenient for the modder's use.
        /// </summary>
        /// <returns>Controller inputs as a custom struct.</returns>
        public ControllerInputs GetControllerState()
        {
            // Instantiate an instance of controller inputs.
            ControllerInputs controllerInputs = new ControllerInputs();

            // Check if controller is connected.
            if (Controller.IsConnected)
            {
                // Update the current state of the Joystick/Controller
                ControllerState = Controller.GetState();

                // Retrieve all of the buttons;
                controllerInputs = GetControllerStateButtons(controllerInputs);

                // Retrieve all of the axis.
                controllerInputs = GetControllerStateAxis(controllerInputs);

                // Retrieve DPAD Information
                GamepadButtonFlags buttonFlags = ControllerState.Gamepad.Buttons;

                if (buttonFlags.HasFlag(GamepadButtonFlags.DPadUp))
                {
                    controllerInputs.ControllerButtons.DpadUp = true;
                }
                if (buttonFlags.HasFlag(GamepadButtonFlags.DPadLeft))
                {
                    controllerInputs.ControllerButtons.DpadLeft = true;
                }
                if (buttonFlags.HasFlag(GamepadButtonFlags.DPadRight))
                {
                    controllerInputs.ControllerButtons.DpadRight = true;
                }
                if (buttonFlags.HasFlag(GamepadButtonFlags.DPadDown))
                {
                    controllerInputs.ControllerButtons.DpadDown = true;
                }

                // Retrieve Emulated Keys
                controllerInputs = GetControllerState_EmulatedKeys(controllerInputs, GetButtons());
            }

            // Return to base.
            return(controllerInputs);
        }
Пример #18
0
        /// <summary>
        /// Emulates a left or right bumper press if any of the triggers are held.
        /// Returns the extra flags to be appended (OR'd) to the existing button flags.
        /// </summary>
        private ButtonFlags SetTriggers(ref ControllerInputs controllerInputs)
        {
            ButtonFlags extraFlags = 0;

            if (ControllerMapping.TriggerOptions.EnableTriggerRotation)
            {
                if (controllerInputs.GetLeftTriggerPressure() > 0)
                {
                    extraFlags |= ControllerMapping.TriggerOptions.SwapTriggers ? ButtonFlags.CameraR : ButtonFlags.CameraL;
                }

                if (controllerInputs.GetRightTriggerPressure() > 0)
                {
                    extraFlags |= ControllerMapping.TriggerOptions.SwapTriggers ? ButtonFlags.CameraL : ButtonFlags.CameraR;
                }
            }

            return(extraFlags);
        }
Пример #19
0
    public bool GetKeyDown(ControllerKeyCode keyCode)
    {
        if (keyCode <= ControllerKeyCode.RightStick)
        {
            return(ControllerInputs.GetControllerValue((int)keyCode, ControllerInputs.ButtonState.Pressed));
        }

        var key = keyCode.ToString().ToLower();

        if (key.Contains("dpad"))
        {
            var axis = dPadAxis.PressedValue;
            switch (keyCode)
            {
            case ControllerKeyCode.DPadUp:
                return(axis.y == 1);

            case ControllerKeyCode.DPadRight:
                return(axis.x == 1);

            case ControllerKeyCode.DPadDown:
                return(axis.y == -1);

            case ControllerKeyCode.DPadLeft:
                return(axis.x == -1);
            }
        }

        if (key.Contains("trigger"))
        {
            if (keyCode == ControllerKeyCode.LeftTrigger)
            {
                return(triggerAxis.pressedValue == -1);
            }
            if (keyCode == ControllerKeyCode.RightTrigger)
            {
                return(triggerAxis.pressedValue == 1);
            }
        }

        return(false);
    }
Пример #20
0
        /// <summary>
        /// Executed upon the loading of the program,
        /// sets the current window as a child of the game window,
        /// allowing the window to be minimized along with the game window, closed
        /// along with the game window etc.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            // Instance members
            _reloadedControllerManager = new ControllerManager();

            // The magic behind following game window.
            _overlayHelper = new WpfOverlayHelper(this, Bindings.TargetProcess.Process.MainWindowHandle);

            // Brings our window to front.
            this.Activate();

            // Always on top (optional)
            // this.Topmost = true;

            // Controller Thread
            Thread controllerThread = new Thread(() =>
            {
                _reloadedControllerManager.SetupControllerManager();

                while (true)
                {
                    // Get inputs.
                    ControllerInputs controllerInputs = _reloadedControllerManager.GetInput(0);

                    // Process inputs.
                    ProcessInputs(controllerInputs);

                    // Wait for button release.
                    while (_reloadedControllerManager.GetInput(0).ControllerButtons.ButtonLs)
                    {
                        Thread.Sleep(16);
                    }

                    // Sleep
                    Thread.Sleep(16);
                }
            });

            controllerThread.Start();
        }
Пример #21
0
        /* Methods (Private) */

        /// <summary>
        /// Iterates over the set of mapping key value pairs and gets the currently enabled Heroes button flags.
        /// Updates the newly set and released buttons entries.
        /// </summary>
        private void SetButtonFlags(ref ControllerInputs controllerInputs)
        {
            ButtonFlags     currentFlags      = 0;
            JoystickButtons controllerButtons = controllerInputs.ControllerButtons;

            // Get the button flags.
            foreach (var keyValue in _controllerMappingDictionary)
            {
                if (keyValue.Value(controllerButtons))
                {
                    currentFlags |= keyValue.Key;
                }
            }

            // Set triggers.
            currentFlags |= SetTriggers(ref controllerInputs);

            // Update struct and last set buttons.
            (*HeroesController).SetPressedButtons(_lastFrameFlags, currentFlags);
            (*HeroesController).SetReleasedButtons(_lastFrameFlags, currentFlags);
            (*HeroesController).SetMinusOneButtonFlags(currentFlags);
            (*HeroesController).ButtonFlags = currentFlags;
            _lastFrameFlags = currentFlags;
        }
 public FloatDescend(ControllerInputs controllerInput, KeyCode keyboardInput, OverworldObject overworldObject) : base(controllerInput, keyboardInput, overworldObject)
 {
 }
 public ToggleTurn(ControllerInputs controllerInput, KeyCode keyboardInput, OverworldObject overworldObject) : base(controllerInput, keyboardInput, overworldObject)
 {
 }
 public ToggleManualMovement(ControllerInputs controllerInput, KeyCode keyboardInput, OverworldObject overworldObject) : base(controllerInput, keyboardInput, overworldObject)
 {
 }
 public UseSkill(ControllerInputs controllerInput, KeyCode keyboardInput, OverworldObject overworldObject, Skill skill) : base(controllerInput, keyboardInput, overworldObject)
 {
     this.skill = skill;
 }
 public OverworldObjectAction(ControllerInputs controllerInput, KeyCode keyboardInput, OverworldObject overworldObject)
 {
     this.controllerInput = controllerInput;
     this.keyboardInput   = keyboardInput;
     this.overworldObject = overworldObject;
 }
Пример #27
0
        /// <summary>
        /// Retrieves the inputs for a specific controller port.
        /// </summary>
        /// <param name="controllerPort">The port of the controller. Starting with port 0.</param>
        public ControllerInputs GetInput(int controllerPort)
        {
            // Retrieve all controllers at port #.
            List <IController> controllersAtPort = Controllers.Where(x => x.InputMappings.ControllerId == controllerPort).ToList();

            // Get input for every controller at port # and add onto the input struct.
            ControllerInputs controllerInputs = new ControllerInputs
            {
                ControllerButtons = new JoystickButtons(),
                LeftStick         = new AnalogStick()
            };

            // For each controller in port #.
            foreach (IController controller in controllersAtPort)
            {
                // Get inputs for the controller.
                ControllerInputs controllerInputsNew = controller.GetControllerState();

                // Add onto Left stick and Right Stick
                controllerInputs.LeftStick.SetX(controllerInputs.LeftStick.GetX() + controllerInputsNew.LeftStick.GetX());
                controllerInputs.LeftStick.SetY(controllerInputs.LeftStick.GetY() + controllerInputsNew.LeftStick.GetY());
                controllerInputs.RightStick.SetX(controllerInputs.RightStick.GetX() + controllerInputsNew.RightStick.GetX());
                controllerInputs.RightStick.SetY(controllerInputs.RightStick.GetY() + controllerInputsNew.RightStick.GetY());

                // Add triggers.
                controllerInputs.SetLeftTriggerPressure(controllerInputs.GetLeftTriggerPressure() + controllerInputsNew.GetLeftTriggerPressure());
                controllerInputs.SetRightTriggerPressure(controllerInputs.GetRightTriggerPressure() + controllerInputsNew.GetRightTriggerPressure());

                // Add DPAD
                if (controllerInputsNew.ControllerButtons.DpadUp)
                {
                    controllerInputs.ControllerButtons.DpadUp = true;
                }
                if (controllerInputsNew.ControllerButtons.DpadLeft)
                {
                    controllerInputs.ControllerButtons.DpadLeft = true;
                }
                if (controllerInputsNew.ControllerButtons.DpadDown)
                {
                    controllerInputs.ControllerButtons.DpadDown = true;
                }
                if (controllerInputsNew.ControllerButtons.DpadRight)
                {
                    controllerInputs.ControllerButtons.DpadRight = true;
                }

                // Add buttons.
                if (controllerInputsNew.ControllerButtons.ButtonA)
                {
                    controllerInputs.ControllerButtons.ButtonA = true;
                }
                if (controllerInputsNew.ControllerButtons.ButtonB)
                {
                    controllerInputs.ControllerButtons.ButtonB = true;
                }
                if (controllerInputsNew.ControllerButtons.ButtonX)
                {
                    controllerInputs.ControllerButtons.ButtonX = true;
                }
                if (controllerInputsNew.ControllerButtons.ButtonY)
                {
                    controllerInputs.ControllerButtons.ButtonY = true;
                }

                if (controllerInputsNew.ControllerButtons.ButtonLb)
                {
                    controllerInputs.ControllerButtons.ButtonLb = true;
                }
                if (controllerInputsNew.ControllerButtons.ButtonRb)
                {
                    controllerInputs.ControllerButtons.ButtonRb = true;
                }
                if (controllerInputsNew.ControllerButtons.ButtonLs)
                {
                    controllerInputs.ControllerButtons.ButtonLs = true;
                }
                if (controllerInputsNew.ControllerButtons.ButtonRs)
                {
                    controllerInputs.ControllerButtons.ButtonRs = true;
                }

                if (controllerInputsNew.ControllerButtons.ButtonBack)
                {
                    controllerInputs.ControllerButtons.ButtonBack = true;
                }
                if (controllerInputsNew.ControllerButtons.ButtonGuide)
                {
                    controllerInputs.ControllerButtons.ButtonGuide = true;
                }
                if (controllerInputsNew.ControllerButtons.ButtonStart)
                {
                    controllerInputs.ControllerButtons.ButtonStart = true;
                }
            }

            // Return port state.
            return(controllerInputs);
        }
 /// <summary>
 /// Sets the controller button associated with activating the overworld object action.
 /// </summary>
 /// <param name="controllerInput">The controller button to set the action to.</param>
 public void SetControllerInput(ControllerInputs controllerInput)
 {
     this.controllerInput = controllerInput;
 }
        /// <summary>
        /// Retrieves and returns the state of all of the inputs that are emulated on a digital (keyboard)
        /// to analog basis to allow the use of e.g. analog sticks within keyboards.
        /// If a non-zero value is set and the button is not pressed, the original value will not be overwritten.
        /// (i.e. Only overrides if input is sent)
        /// </summary>
        /// <returns></returns>
        private ControllerInputs GetControllerState_EmulatedKeys(ControllerInputs controllerInputs, bool[] buttons)
        {
            // Retrieve Emulated DPAD Keys
            #region DPAD Keys
            if (InputMappings.EmulationMapping.DpadDown != ButtonNull)
            {
                // Retrieve the button index for the emulated button.
                int buttonIndex = DInputGetEmulatedButtonIndex(EmulatedButtonsGeneric.DpadDown, InputMappings.EmulationMapping);

                // Check if button is pressed.
                bool isPressed = buttons[buttonIndex];

                // If it is pressed, override the current value to include the flag.
                if (isPressed)
                {
                    controllerInputs.ControllerButtons.DpadDown = true;
                }
            }
            if (InputMappings.EmulationMapping.DpadLeft != ButtonNull)
            {
                // Retrieve the button index for the emulated button.
                int buttonIndex = DInputGetEmulatedButtonIndex(EmulatedButtonsGeneric.DpadLeft, InputMappings.EmulationMapping);

                // Check if button is pressed.
                bool isPressed = buttons[buttonIndex];

                // If it is pressed, override the current value to include the flag.
                if (isPressed)
                {
                    controllerInputs.ControllerButtons.DpadLeft = true;
                }
            }
            if (InputMappings.EmulationMapping.DpadRight != ButtonNull)
            {
                // Retrieve the button index for the emulated button.
                int buttonIndex = DInputGetEmulatedButtonIndex(EmulatedButtonsGeneric.DpadRight, InputMappings.EmulationMapping);

                // Check if button is pressed.
                bool isPressed = buttons[buttonIndex];

                // If it is pressed, override the current value to include the flag.
                if (isPressed)
                {
                    controllerInputs.ControllerButtons.DpadRight = true;
                }
            }
            if (InputMappings.EmulationMapping.DpadUp != ButtonNull)
            {
                // Retrieve the button index for the emulated button.
                int buttonIndex = DInputGetEmulatedButtonIndex(EmulatedButtonsGeneric.DpadUp, InputMappings.EmulationMapping);

                // Check if button is pressed.
                bool isPressed = buttons[buttonIndex];

                // If it is pressed, override the current value to include the flag.
                if (isPressed)
                {
                    controllerInputs.ControllerButtons.DpadUp = true;
                }
            }
            #endregion

            // Retrieve Emulated Left Analog Stick
            #region Left Analog Stick
            if (InputMappings.EmulationMapping.LeftStickDown != ButtonNull)
            {
                // Retrieve the button index for the emulated button.
                int buttonIndex = DInputGetEmulatedButtonIndex(EmulatedButtonsGeneric.LeftStickDown, InputMappings.EmulationMapping);

                // Check if button is pressed.
                bool isPressed = buttons[buttonIndex];

                // If the stick value is not 0 and is not pressed, do not override.
                if (isPressed)
                {
                    controllerInputs.LeftStick.SetY(controllerInputs.LeftStick.GetY() + AxisMaxValueF);
                }
            }

            if (InputMappings.EmulationMapping.LeftStickLeft != ButtonNull)
            {
                // Retrieve the button index for the emulated button.
                int buttonIndex = DInputGetEmulatedButtonIndex(EmulatedButtonsGeneric.LeftStickLeft, InputMappings.EmulationMapping);

                // Check if button is pressed.
                bool isPressed = buttons[buttonIndex];

                // If the stick value is not 0 and is not pressed, do not override.
                if (isPressed)
                {
                    controllerInputs.LeftStick.SetX(controllerInputs.LeftStick.GetX() - AxisMaxValueF);
                }
            }

            if (InputMappings.EmulationMapping.LeftStickRight != ButtonNull)
            {
                // Retrieve the button index for the emulated button.
                int buttonIndex = DInputGetEmulatedButtonIndex(EmulatedButtonsGeneric.LeftStickRight, InputMappings.EmulationMapping);

                // Check if button is pressed.
                bool isPressed = buttons[buttonIndex];

                // If the stick value is not 0 and is not pressed, do not override.
                if (isPressed)
                {
                    controllerInputs.LeftStick.SetX(controllerInputs.LeftStick.GetX() + AxisMaxValueF);
                }
            }

            if (InputMappings.EmulationMapping.LeftStickUp != ButtonNull)
            {
                // Retrieve the button index for the emulated button.
                int buttonIndex = DInputGetEmulatedButtonIndex(EmulatedButtonsGeneric.LeftStickUp, InputMappings.EmulationMapping);

                // Check if button is pressed.
                bool isPressed = buttons[buttonIndex];

                // If the stick value is not 0 and is not pressed, do not override.
                if (isPressed)
                {
                    controllerInputs.LeftStick.SetY(controllerInputs.LeftStick.GetY() - AxisMaxValueF);
                }
            }
            #endregion

            // Retrieve Emulated Right Analog Stick
            #region Right Analog Stick
            if (InputMappings.EmulationMapping.RightStickDown != ButtonNull)
            {
                // Retrieve the button index for the emulated button.
                int buttonIndex = DInputGetEmulatedButtonIndex(EmulatedButtonsGeneric.RightStickDown, InputMappings.EmulationMapping);

                // Check if button is pressed.
                bool isPressed = buttons[buttonIndex];

                // If the stick value is not 0 and is not pressed, do not override.
                if (isPressed)
                {
                    controllerInputs.RightStick.SetY(controllerInputs.RightStick.GetY() + AxisMaxValueF);
                }
            }

            if (InputMappings.EmulationMapping.RightStickLeft != ButtonNull)
            {
                // Retrieve the button index for the emulated button.
                int buttonIndex = DInputGetEmulatedButtonIndex(EmulatedButtonsGeneric.RightStickLeft, InputMappings.EmulationMapping);

                // Check if button is pressed.
                bool isPressed = buttons[buttonIndex];

                // If the stick value is not 0 and is not pressed, do not override.
                if (isPressed)
                {
                    controllerInputs.RightStick.SetX(controllerInputs.RightStick.GetX() - AxisMaxValueF);
                }
            }

            if (InputMappings.EmulationMapping.RightStickRight != ButtonNull)
            {
                // Retrieve the button index for the emulated button.
                int buttonIndex = DInputGetEmulatedButtonIndex(EmulatedButtonsGeneric.RightStickRight, InputMappings.EmulationMapping);

                // Check if button is pressed.
                bool isPressed = buttons[buttonIndex];

                // If the stick value is not 0 and is not pressed, do not override.
                if (isPressed)
                {
                    controllerInputs.RightStick.SetX(controllerInputs.RightStick.GetX() + AxisMaxValueF);
                }
            }

            if (InputMappings.EmulationMapping.RightStickUp != ButtonNull)
            {
                // Retrieve the button index for the emulated button.
                int buttonIndex = DInputGetEmulatedButtonIndex(EmulatedButtonsGeneric.RightStickUp, InputMappings.EmulationMapping);

                // Check if button is pressed.
                bool isPressed = buttons[buttonIndex];

                // If the stick value is not 0 and is not pressed, do not override.
                if (isPressed)
                {
                    controllerInputs.RightStick.SetY(controllerInputs.RightStick.GetY() - AxisMaxValueF);
                }
            }
            #endregion

            // Retrieve Emulated Triggers
            #region Triggers
            if (InputMappings.EmulationMapping.RightTrigger != ButtonNull)
            {
                // Retrieve the button index for the emulated button.
                int buttonIndex = DInputGetEmulatedButtonIndex(EmulatedButtonsGeneric.RightTrigger, InputMappings.EmulationMapping);

                // Check if button is pressed.
                bool isPressed = buttons[buttonIndex];

                // If the stick value is not 0 and is not pressed, do not override.
                if (isPressed)
                {
                    controllerInputs.SetRightTriggerPressure(AxisMaxValueF / DInputManager.TriggerScaleFactor);
                }
            }

            if (InputMappings.EmulationMapping.LeftTrigger != ButtonNull)
            {
                // Retrieve the button index for the emulated button.
                int buttonIndex = DInputGetEmulatedButtonIndex(EmulatedButtonsGeneric.LeftTrigger, InputMappings.EmulationMapping);

                // Check if button is pressed.
                bool isPressed = buttons[buttonIndex];

                // If the stick value is not 0 and is not pressed, do not override.
                if (isPressed)
                {
                    controllerInputs.SetLeftTriggerPressure(AxisMaxValueF / DInputManager.TriggerScaleFactor);
                }
            }
            #endregion

            // Return controller inputs
            return(controllerInputs);
        }
Пример #30
0
 /// <summary>
 /// Passes on the controls to the individual game.
 /// </summary>
 /// <param name="controllerInputs"></param>
 public void SetControls(ref ControllerInputs controllerInputs)
 {
     SetButtonFlags(ref controllerInputs);
     SetSticks(ref controllerInputs);
 }