Search Unity

Rewired - Advanced Input for Unity

Discussion in 'Assets and Asset Store' started by guavaman, Sep 25, 2014.

  1. crypt0

    crypt0

    Joined:
    May 25, 2015
    Posts:
    55
    Hi,

    thanks for your response even if it is not as I hoped. I know that a normal Joystick centered but the throttle stick (vertically) of a rc transmitter doesn't...then I have to look for another solution....arghh

    Thanks and cheers
     
  2. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    Howso? The script I posted does exactly what you wanted and could be easily modified to do all kinds of similar variations. Add the component to the Touch Joystick GameObject and it will work.
     
    Last edited: Apr 4, 2017
  3. crypt0

    crypt0

    Joined:
    May 25, 2015
    Posts:
    55
    Ah - (facepalm) I have not read the text correctly because it was a long day. I tought the script only for the initial value. I didn't checked the script. Thanks man!

    Cheers
     
  4. friuns3

    friuns3

    Joined:
    Oct 30, 2009
    Posts:
    307
  5. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    Sort of. WebGL uses UnityEngine.Input for the input source. There is no auto-recognition of devices on WebGL at this time.

    From the FAQ:

    Can you add joystick auto-recognition for WebGL?
    At this time, joysticks on WebGL are only supported via manual user mapping of controls at runtime through the use of a system like Control Mapper.

    WebGL controller support is very poor at this time with a huge number of cross-browser bugs and inconsistencies. These inconsistencies even vary across different versions of the same browser on one OS, and across the same versions of the same browser across different OS's. This makes it highly impractical to provide controller auto-recognition for WebGL because it would require code to detect OS, browser, and browser version and require potentially dozens more controller definitions for each controller Rewired supports. Even then, there are many bugs that cannot be fixed which simply make the use of joysticks sub-optimal and would result in a frustrating user experience.
     
    Last edited: Apr 6, 2017
  6. canis

    canis

    Joined:
    Oct 25, 2013
    Posts:
    79
    Hi Guavman,
    Question 1)
    I would like to made a script to easier trigger some logic for other class.
    however, I found it's very hard to Fetch the exist key { string, id } data from your plugin.
    since I'm new for your plugin would you please to tell me is there are some existing method are doing the same thing ?
    rewird_key_toggle.PNG

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Events;
    3. using System.Collections;
    4. using Rewired;
    5.  
    6. public class RewiredInputHelper : MonoBehaviour
    7. {
    8.     [SerializeField] int m_PlayerId = 0;
    9.     [SerializeField] string m_RewiredKeyName = "";
    10.     [SerializeField] InputActionEventType m_EventType = InputActionEventType.ButtonUnpressed;
    11.     [SerializeField] UpdateLoopType m_UpdateType = UpdateLoopType.Update;
    12.  
    13.     public UnityEvent OnTrigger;
    14.  
    15.     IEnumerator Start()
    16.     {
    17.         yield return new WaitUntil(() => ReInput.isReady);
    18.         Player player = ReInput.players.GetPlayer(m_PlayerId);
    19.         InputAction action = ReInput.mapping.GetAction(m_RewiredKeyName);
    20.         player.AddInputEventDelegate(InputCallback, m_UpdateType, m_EventType, action.id);
    21.     }
    22.  
    23.     private void InputCallback(InputActionEventData evtData)
    24.     {
    25.         OnTrigger.Invoke();
    26.     }
    27. }
    28.  
    Question 2)
    is that a method to identify the player[0] are using Keyboard or using GamePad ??
    I mean they both active at the same time, but I would like to know the latest input are keyboard or GamePad or joystick...etc
    because I wanted to switch the UI hit based on user native input device source.
     
  7. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    Answers to both questions are on the same page of the documentation:

    1) How To's: Displaying a drop-down list of Actions in the inspector of a script
    2a) How To's: Determining which Controller was last used
    2b) How To's: Getting contributing input sources for an Action
     
    canis likes this.
  8. MrG

    MrG

    Joined:
    Oct 6, 2012
    Posts:
    368
    Does Rewired handle mouse input in RDP session? Unity fails to detect the mouse movement, so the normal mouse-look scripts all fail. Clicks work fine, but not the movement.
     
  9. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    I don't know. That has never been tested. When Native Mouse Handling is enabled on Windows, WM_INPUT messages are used for mouse input. If those are delivered to the window, then it would work. If not, it won't.

    You can test all features of Rewired with the free trial on the website.
     
  10. greengremline

    greengremline

    Joined:
    Sep 16, 2015
    Posts:
    183
    Hey! How's it going? First of all, just wanna say that this asset rocks - well worth the money spent!

    Your documentation is really solid, and I've been able to do most of the work replacing Unity's native input with Rewired. I do have a question, though. My entire UI is on a single canvas. Is it possible to use my own canvas to place the ControlMapper on, instead of it's own canvas? I'd like to have it slot in to my existing menu structure.
     
    Last edited: Apr 8, 2017
  11. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    Thanks!

    You can modify Control Mapper in any way you want. It's all Unity UI based. If you know what you're doing with Unity UI, you can make it do anything. However the only supported configuration (that I can provide support for) is the original configuration.

    If you replace the canvas, the Canvas Scaler Fitter component on the Control Mapper Canvas will no longer work. This component is responsible for making it fit on different aspect ratio screens.

    The Canvas reference in the References section of the inspector must be linked to a Canvas of some kind. If you delete the Canvas that comes on it, this reference will be blank and you will get null reference errors.

    There is information in the documentation on doing modifications beyond customizing inspector settings in the FAQ: http://guavaman.com/projects/rewired/docs/ControlMapper.html#faq
     
  12. greengremline

    greengremline

    Joined:
    Sep 16, 2015
    Posts:
    183
    Awesome! Thanks so much
     
  13. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    @guavaman @Steve-Tack

    Here are some really nice flight controls and I am sure they have a price to match. It is nice to have true simulation grade equipment and they all have USB connectors options too.

    The F-16 desktop control was expected around $2800 or so I have seen posted elsewhere. http://www.f-16grips.com/

    There main website they have also sorts of interesting controls (stick/throttle/pedals/cockpit accessories) for fighter jets and helicopters, plus cockpits too.

    https://www.bugeyetech.com/

    The apache gunner controller are really interesting on how many buttons they have on that stick. That would be fun controller to map in Rewired.

    https://www.bugeyetech.com/ah-64

    The desktop adapter they have for HOTAS is really amazing too. This what got my interest originally as something that would probably be really useful.

    https://www.bugeyetech.com/desk-top-adapter

    The ejection seats are really nice too.

    https://www.bugeyetech.com/seats
     
    guavaman likes this.
  14. Karearea

    Karearea

    Joined:
    Sep 3, 2012
    Posts:
    386
    Wow, very cool. You'd need to simulate the F-35 helmet. Maybe a VR headset, with the 'real' cockpit view modelled around you, and then the overlaid view from external cameras on top of that? or build the physical cockpit to go with the beautiful flightstick, and then simulate it with a hololens.
     
  15. emrys90

    emrys90

    Joined:
    Oct 14, 2013
    Posts:
    755
    How can I set what the last active controller is? When a gamepad is connected I want to set it as being last active so that rewiredPlayer.controllers.GetLastActiveController() returns that controller.
     
  16. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    You can't. Last active controller is determined by input the player has generated by using the controller or keyboard, etc. If the player hasn't moved a stick or pressed a button on the controller, it won't be considered the last active controller. This is all calculated based on the last timestamp of an active element.
     
  17. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    They are nice controls indeed. Did not look at the F-35 too much but I see what you mean.

    Did not even think of the F-35 helmet part but the hololens part seems like a perfect choice to work with such controls.
     
  18. dotsquid

    dotsquid

    Joined:
    Aug 11, 2016
    Posts:
    224
    Hi @guavaman
    Thanks for such a beautiful library!
    How about a tiny improvement which can make happy those who aim to clear code? :)
    My proposition is to add keyword "partial" to the class which is auto-generated from Rewired Editor > Tools.
    This would allow to reuse and expand this class from another files/scripts.
     
  19. crypt0

    crypt0

    Joined:
    May 25, 2015
    Posts:
    55
    Hi,
    where/how can I remove the joysticks+/- fields in the control mapper UI? So, that my changes are not overwritten with the next update.

    Cheers
     
  20. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    From the Control Mapper documentation:

    rw.jpg
     
  21. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    Which class? The wrapper class (which is optional), the Actions class, the Players class, the Map Category class, the Layout classes (3 of them), the Custom Controller classes (one per controller)? There are many things which can be exported from this tool, all of which are optional. I think if you want to re-use one of these classes for some reason, it is extremely simple to add the partial keyword to the class(es) you want to re-use. Exporting constants from the tool is probably something you'll do 1 to a few times per project max.

    Do you have an example use case for this? I don't really see the usefulness in re-using these classes for your own purposes since they exist for auto-generated data and at the most would save you from making one extra class for your own non-auto-generated content. And if you use the namespace option, you can make your own classes in there if organization is the concern. In addition, making them partial classes and encouraging you to make your own members in those classes leads to the possibility of member name clashes when generating the consts.
     
    Last edited: Apr 11, 2017
  22. Wuzseen

    Wuzseen

    Joined:
    Apr 19, 2011
    Posts:
    20
    Hey there! Rewired is a huge help in my personal & studio projects.

    Was curious--will there be a TextMesh Pro version of the control remapper (now that TMP is free)? I'd love to update a project to the more recent Rewired versions but unfortunately I'd lose our text mesh pro version of the control remapper (well, I'd have to redo it as I edited some rewired scripts directly). If this is something down the pipeline I'd wait on updating but if it's not I might as well update and take the steps to write my own remapping interface.
     
  23. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    I'm glad you're getting use out of it!

    I have no plans on making a new version of Control Mapper with TextMesh Pro. Perhaps when that becomes part of the engine, but I currently have no plans to do that.

    You should never modify the scripts directly for exactly that reason. You can make a copy of the scripts that you need to modify, copies of the prefabs you need to modify, then change the prefabs/scene objects to use your scripts instead of the ones that come with Rewired. Control Mapper also has inspector fields to replace the prefabs used for dynamic UI elements.

    1.1.0.0 includes the Input Mapper class which makes creating your own remapping UI a lot easier.
     
  24. dotsquid

    dotsquid

    Joined:
    Aug 11, 2016
    Posts:
    224
    Sorry for ambiguities. I meant the wrapper class.
    Here is our situation.
    We have a namespace called Consts which contains several static classes each of which represents a group of consts. E.g. ButtonName, Conditional, Input. Through Rewired Editor we export consts into Consts.Input. But apart of internal classes exported by Rewired (Actions, Layouts etc) we'd like to have some extra data in Consts.Input.
    Surely we could add "partial" manually every time we export the consts from Rewired, but it's not a true engineering way, you know ;)
    Fortunately C# allows having only one "part" of the class if it was marked as "partial". So no one's code will be hurt if you add "partial" to the wrapper class.
     
  25. zhuchun

    zhuchun

    Joined:
    Aug 11, 2012
    Posts:
    433
    Hi, does Rewired support simulate cursor based on controller input?
     
  26. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    Hi,

    No, Rewired doesn't do anything with the cursor, hardware or software.
     
  27. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    Thanks for the clarification and use case.

    I will add partial to all classes exported by the tool. To be honest, I can't see this being used by anyone else, but I'll add it nonetheless.
     
  28. Vampyr_Engel

    Vampyr_Engel

    Joined:
    Dec 17, 2014
    Posts:
    449
    Lovely though very very expensive think these controls would suit someone building a homemade cockpit simulator in your basement or spare room to be frank rather than just have t as a desktop controller
     
  29. dotsquid

    dotsquid

    Joined:
    Aug 11, 2016
    Posts:
    224
    Thanks!
    I believe there is no need to add "partial" to nested classes like Actions, Layouts etc. Because that would indeed be error-prone for the end user. Partial wrapper class is enough.
     
  30. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    I am going to go ahead and make them all partial anyway in case someone else has an obscure use case for it. They will just have to properly manage their member names to avoid clashes.
     
  31. greengremline

    greengremline

    Joined:
    Sep 16, 2015
    Posts:
    183
    So I was wondering if it's possible to do something similar to rewiredPlayer.IsCurrentInputSource("Look Horizontal", ControllerType.Joystick) but find the last input source that contributed to that action (for example, I have a switch that performs different look sensitivity speeds depending on input source, which needs to continue even after the player lets go of the controls or it might feel janky)
     
  32. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    How To's - Getting contributing input sources for an Action
    I don't know how letting go of the controls would have any effect on your look sensitivity. If you set the sensitivity based on when the last used input type changes, it wouldn't matter whether the player let go of the controls because the last used input type isn't going to change again until they use some other control.

    See this for last used controller type:
    How To's - Determining which Controller was last used
     
  33. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    By the way, the Input Behavior has per-device-type axis sensitivity settings you can use exactly for this purpose.
     
    greengremline likes this.
  34. greengremline

    greengremline

    Joined:
    Sep 16, 2015
    Posts:
    183
    Awesome thanks so much! I'll dive deeper into the documentation going forward
     
  35. dotsquid

    dotsquid

    Joined:
    Aug 11, 2016
    Posts:
    224
    Hi there again.
    I've encountered some weirdness.

    1. For some reason Rewired Tool exports wrong player Ids: they do not match the real ones.


    2. XBox One Controller is recognized as XBox 360 Controller on Windows 10 and Windows 10 Anniversary Update. Rewired returns GUID {d74a350e-fe8b-4e9e-bbcd-efff16d34115}.
    Rewired has following settings:
    Primary input source: RawInput;
    Use XInput: true
     
  36. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    Thanks. This is a bug. The editor uses a different internal id for Players than in the game. They are converted to a 0 index for the game but in the editor it uses a unique id that's incremented every time you create a new user. When generating the list, I did convert to an index, but neglected to subtract 1 for the System Player which occupies index 0. Thanks for pointing this out.

    That's correct. It's explained here:

    Controller Maps - Special Considerations for XInput gamepads on Windows Standalone, Windows App Store, and Windows 10 Universal

    Also noted and linked from here:
    How To's - Identifying recognized Joysticks by type
     
    Last edited: Apr 13, 2017
  37. dotsquid

    dotsquid

    Joined:
    Aug 11, 2016
    Posts:
    224
    And now I'm more confused than before.
    The things are as follows:
    1. We use RawInput as input source with XInput enabled. As far as I understand, this means that for Windows Rewired will use XInput and for other platforms raw data from device.
    XInput gives us all the benefits of civilization: vibration, support of Steam controller and other Steam features, unified controller mapping (as Dual Analog Gamepad) etc. So XInput is a must.

    2. We must display some tips with glyphs of gamepad buttons for our gamers so they know how to play. Since we're aiming to cover the majority of gamepads we'd like to show different tips for different controllers: specifically we won't to show tips for XBox-like controllers, DualShocks and SteamControllers.
    So we have to know the name/type of controller being used.

    3. As far as I understand your docs, if we use XInput all XInput-compatible controller it will be always detected as "XInput Gamepad".
    But strangely enough DualShock4 is detected as DualShock4. And Logitech Precision is detected as Logitech Precision.

    So I wonder, are XBox-like controllers the only controllers which aren't detected correctly and are shown as XBox 360 Controller?
     
  38. dotsquid

    dotsquid

    Joined:
    Aug 11, 2016
    Posts:
    224
    Ok, it seems I can just check Joystick.hardwareTypeGuid.
    XBox 360 and XBox One controllers will be considered as "just some XBox controller". It's ok for us.
    Thanks, sorry for bothering.
     
  39. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    Do you have enhanced device support enabled for Windows? See Exhibit A for screen shot.

    Because with enhanced device support that gives you other feature for the dual shock4 as mentioned in the documentation here.

    http://guavaman.com/projects/rewired/docs/HowTos.html#dualshock-4-special-features


    Exhibit A:

    rewired_enhanced_device_support.JPG
     
  40. dotsquid

    dotsquid

    Joined:
    Aug 11, 2016
    Posts:
    224
    Actually that's not what I was asking about. But thanks and yes, Enhanced Device Support is enabled.
     
  41. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    DualShock4 is not XInput-compatible. It does not appear as an XInput device unless the user has a program installed to create an emulated XInput device for it such as DS4Win or if they have DS4 remapping support enabled in Steam's Big Picture mode. Steam is complicating things because they are slowly adding XInput emulation for more devices through Big Picture. These are not really XInput-compatible devices, but they are making them appear so to the system so they can fit them into the same mold so their Steam controller mapping system will work and make the games see them all as XInput devices.

    Logitech Precision probably is not XInput compatible either. Logitech F310, 510, 710 are XInput compatible but only if the switch is flipped to the "X" mode. Many gamepads have "XInput" and "Direct Input" modes.

    That is correct and what the docs say to do:
    http://guavaman.com/projects/rewired/docs/HowTos.html#display-glyph-for-action
    http://guavaman.com/projects/rewired/docs/HowTos.html#identifying-recognized-controllers

    You will have to set up glyphs for XBox 360 Controller which will cover X360 and all XInput-compatible devices on Windows, but also XBox One Controller for OSX/Linux/Other systems. Logitech F310, 510, 710, and all other XInput-compatible gamepads will work on Windows as XBox 360 Controller (assuming they're set to X mode), but will need glyphs set up for other platforms for those specific devices.
     
  42. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    Rewired 1.1.1.0 is now available for registered users to download from the Rewired website. If you'd like to receive early access to updates, please contact me here. The Unity Asset Store should get this update in 5-10 business days.
    Please note: This update does not include Nintendo Switch support. The new definitions for the Joy-Con and Pro Controller only apply to non-Switch platforms at present.

    Release Notes:

    1.1.1.0:

    Changes:
    - Windows Standalone, XInput: Eliminated periodic lag on some versions of Windows/XInput when checking for device changes.
    - Added "partial" keyword to all constant classes exported from the Rewired Input Manager.

    New Controller Definitions:
    - Nvidia Shield Controller (2017 model)
    - Nintendo Switch Joy-Con (Left)
    - Nintendo Switch Joy-Con (Right)
    - Nintendo Switch Pro Controller

    API Changes:
    - Added ComponentControls.TouchJoystick.GetValue method.
    - Added ComponentControls.TouchJoystick.GetRawValue method.

    Bug fixes:
    - Touch Joystick now re-centers stick to the Axis 2D calibrated zero instead of Vector2.zero.
    - Windows Standalone, Raw Input, Use XInput disabled: Added workaround for issue causing Xbox One controller to fail to return input when attaching Visual Studio debugger to Unity editor.
    - Fixed incorrect Player Id exported when exporting Players to constants from Rewired Editor.
     
  43. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    That would be ideal. I was just looking at pricing for joysticks from the manufacturer point of view and it is really expensive when you have very low production runs.

    I was just looking at the APEM (CH Products is part of the APEM) joystick and it is $462 at digikey for just one. This one is also dust proof and water proof so that might be something additional plus it is rated to 10 million cycles. That is using a standard part and not creating your own mold for you own joystick.

    https://www.digikey.com/product-detail/en/apem-inc/CJ-N3DP0013N/1040-1029-ND/3507466

    It is also interesting that digikey does carry CH Products' consumer flight sim products too. I would have never thought of looking at digikey for CH Fighterstick but that might be a good choice in the future if amazon and all of the normal flight simulation stores do not have any product.
     
  44. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    That was really quick to get those Nintendo Switch controllers available for the PC. Nice. It is amazing how many different gamepads there are too.
     
  45. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    Unfortuantely, they don't work as well as one would hope. The Joy-Con sticks return digital hat values when connected to a PC, not a range of values like other sticks. The gyros and vibration are also unavailable on both Joy-Cons and Pro Controller. It should be possible to get this data through direct HID communication, but thus far I've only been partially successful. Early info on this that I've found doesn't seem to work on Windows in my testing.
     
  46. dotsquid

    dotsquid

    Joined:
    Aug 11, 2016
    Posts:
    224
    Thanks for quick fix of Player Ids and adding "partial" to exported classes. Really appreciate that.
     
    guavaman likes this.
  47. crudeMe

    crudeMe

    Joined:
    Jul 8, 2015
    Posts:
    92
    Hi! Is there a way to set up a steering wheel range of operation (degrees of rotation)?
     
  48. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    No. This is handled in the driver software for the steering wheel.

    Otherwise, calibration determines an axis's range of movement.
     
    Last edited: Apr 19, 2017
    crudeMe likes this.
  49. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    It appears that calibration link URL is wrong since it does not resolve itself.
     
  50. MrG

    MrG

    Joined:
    Oct 6, 2012
    Posts:
    368