Search Unity

InControl - input and cross platform controller support for Unity, made easy!

Discussion in 'Assets and Asset Store' started by pbhogan, Jul 18, 2014.

  1. mbowen89

    mbowen89

    Joined:
    Jan 21, 2013
    Posts:
    639
    Just an FYI that as of right now on Win 8.1, the NVIDIA Shield controller plugged in via USB on Windows has a different control profile than set in your current release. I copied the Analog stick profile section from the NVIDIA Shield for Android profile and it works like normal.
     
  2. pbhogan

    pbhogan

    Joined:
    Aug 17, 2012
    Posts:
    384
    Hmm, I'll check it out. Thanks!
     
  3. ottolb

    ottolb

    Joined:
    Jul 1, 2009
    Posts:
    42
    Hey Patrick,
    I just updated to Unity 5.1.3 and they changed a method that is causing compiling errors.
    Here is what a changed in InControlInputModule (line 200) class to fix it:
    Code (CSharp):
    1. #if UNITY_5_1_3
    2.     var mouseData = GetMousePointerEventData(0);
    3. #else
    4.     var mouseData = GetMousePointerEventData();
    5. #endif
     
  4. pbhogan

    pbhogan

    Joined:
    Aug 17, 2012
    Posts:
    384
    The change is actually a bug by Unity. I have an update to fix this waiting for Unity to approve for over a week now. :(

    It also affects Unity 4.6.8, but was fixed in Unity 4.6.8p1 so I anticipate it will be fixed in 5.1.3p2 also. Of course Unity fixing it means it will break InControl for the patch releases since there aren't any preprocessor guards for specific patch releases. :rolleyes:
     
    ottolb likes this.
  5. djfrail

    djfrail

    Joined:
    Jan 16, 2014
    Posts:
    124
    I'm messing around with XInput (did the XInputDotNet setup) and it seems to work fine when I run the game from the .exe but in the editor I'm not able to use my game controller. It says in the console "Device 1 matching profile Xbox360WinProfile (XBox 360 Controller) is hidden and will not be attached." Not sure why that says that. Also it worked in the editor before I enabled XInput.

    Also - should I even be using XInput? I would prefer to use the method that supports the most controllers but my game only need to use one controller at a time and fast polling isn't important.
     
  6. pbhogan

    pbhogan

    Joined:
    Aug 17, 2012
    Posts:
    384
    You might just take a look at http://www.gallantgames.com/pages/incontrol-xinput and make sure you have all the required steps completed. If you're using Unity 4, you might need to copy the DLLs to the root of your project. Although usually there's some kind of error in the console when the DLLs can't be found. It could even be that it's working the other way around... that XInput is working in editor but not detecting your controller and is actually not working with the .exe build and falling back to regular Unity input. Have you tried building the TestInputManager scene to .exe to see which it is actually using? Sometimes it seems like systems need DirectX or the Xbox 360 driver reinstalled to work with XInput.

    The console message is just letting you know that the regular Unity device profile won't be used for that specific controller since XInput is activated. It could probably be better phrased... :)

    In any event, you don't really need to use XInput unless you're running into a problem or need the features it provides.
     
  7. djfrail

    djfrail

    Joined:
    Jan 16, 2014
    Posts:
    124
    I choose this option - thanks!
     
  8. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,157
    Is there an easier way to detect if any input has been registered on the input device than this:

    Code (CSharp):
    1.         if (inputDevice.RightStick.IsPressed ||
    2.             inputDevice.LeftStick.IsPressed ||
    3.             inputDevice.AnyButton.IsPressed ||
    4.             inputDevice.RightBumper.IsPressed ||
    5.             inputDevice.LeftBumper.IsPressed ||
    6.             inputDevice.DPad.IsPressed) {
    7.             timerTime = 0f;
    8.         }
    I mean, it works, but it's hardly the most elegant solution in the universe.
     
  9. Foxxis

    Foxxis

    Joined:
    Jun 27, 2006
    Posts:
    1,108
    Hi,

    When upgrading upgrading our project (currently running 4.6.8) to the latest version of InControl, I get the following error:
    I have tried moving the XInput DLLs to the plugin folder, but it still will not compile. I am not even sure we would like to use XInput. Either way, what would be the best way to solve the issue? Thanks in advance!
     
  10. Foxxis

    Foxxis

    Joined:
    Jun 27, 2006
    Posts:
    1,108
    Maybe I managed to get rid of that error by removing the entire InControl folder and reimporting. However, I cannot be sure yet as I got a bunch of other errors relating to my use of Incontrol. For example:
    It appears RightStickX has been removed in favour of RightStickRight/Left. So the control type cannot be a full axis any more? I would appreciate some info on why this was changed and the intended use. It looks like it will upend our code that hooks into InControl. :-(
     
  11. pbhogan

    pbhogan

    Joined:
    Aug 17, 2012
    Posts:
    384
    There isn't a direct InputDevice.HasChanged property, but there is an InputDevice.LastChangeTick property that changes when input has updated on the device. You can use that to determine whether there's been a change by saving it and comparing it to your saved value.
     
  12. pbhogan

    pbhogan

    Joined:
    Aug 17, 2012
    Posts:
    384
    Yes, I made that change to support the new bindings system and it simplified a lot of the internal implementation. I’m sorry it broke your system—I do try hard not to make breaking changes, but this one seemed necessary and it affected very few users. Adding them back creates confusing situations to users in general such as they wouldn’t work with the bindings API, or in device profile mappings.

    So that said, I think your best bet is to create your own enum and switch on it to pull from InControl. The InputDevice.LeftStickX etc. properties still exist, there just aren’t entries in the InputControlType enum for them. You could even copy InControl’s enum wholesale (if you want all the entries) and tack on the additional four at the end with explicit high values to leave room if InControl’s grows in the future. Then pass all those of lower value directly to InControl’s GetControl() with a cast and handle the additions with calls to the properties. Hopefully that makes sense.
     
  13. Foxxis

    Foxxis

    Joined:
    Jun 27, 2006
    Posts:
    1,108
    Thanks Patrick, and thanks for the swift reply via email as well.
    We will have to update our code to work with the new version. Will take a few hours but will likely be worth it as InControl has worked flawlessly for us previously.
     
  14. silentneedle

    silentneedle

    Joined:
    Mar 14, 2013
    Posts:
    280
    I'm currently working on a chat module for a clients project. Is there any proper way to disable all actions except my ChatAction?

    What I'm trying is to avoid other actions like jumping when the player is typing in the chatbox.
     
  15. Tuni

    Tuni

    Joined:
    May 24, 2013
    Posts:
    74
    The Xbox One controller mappings for OS X seems to be wrong. Can someone confirm that? The driver has a live preview of the controller in the system preferences. There are all mappings correct.
     
  16. Hugbot

    Hugbot

    Joined:
    Jul 10, 2013
    Posts:
    10
    Hi @pbhogan,

    I love your asset!

    I'm not sure if this has been answered elsewhere, but I was wondering if there is a way to limit the touch stick UI input to only the x axis? Currently for my game I only need to worry about moving left and right, because of that I'd like to make it so that the UI component can only go left and right, not up and down as well.

    I know that on the programming side you can use OneAxis, in order to associate that input, but this question is mostly with regard to the UI portion of the touch stick control.

    Is there a mechanism to limit the mobility of the UI portion so that it can only be updated on the X-Axis, and not both the X and Y axis?
     
  17. rsodre

    rsodre

    Joined:
    May 9, 2012
    Posts:
    229
  18. mbowen89

    mbowen89

    Joined:
    Jan 21, 2013
    Posts:
    639
    I'm in the AppleTV beta and I have InControl working with it already... it only needs a new device profile really to even get working... nothing special!
     
  19. gameDevi

    gameDevi

    Joined:
    Oct 14, 2015
    Posts:
    155
    How do I keep the touch buttons resizing depending on the size of canvas size?

    if the screen size shrinks the incontrol buttons go off screen. what can I do to fix this?

    Also; I have to players on screen. I have some basic navigation buttons on left of the screen for player 1 and the navigation buttons on the right of the screen for player 2. What would be the best way to do this?

    do you have any example with ugui integration?

    also can I tell input control that DPadUp has been pressed when a ugui button is pressed?
     
    Last edited: Oct 30, 2015
  20. djfrail

    djfrail

    Joined:
    Jan 16, 2014
    Posts:
    124
    I'm testing out my game on an Android tablet with different game controllers connected via a USB OTG cable. The Xbox 360 and PS4 controllers both work fine to operate Android itself. The 360 controller works great in my game, but the PS4 controller stick and dpad moves are too fast and the buttons are mapped differently.

    Any ideas why? I'm using Unity 4.6.9 and InControl 1.5.12 b6554.
     
  21. mbowen89

    mbowen89

    Joined:
    Jan 21, 2013
    Posts:
    639
    Modify the profile for the PS4 controller for Android. Do you know how to do that?
     
  22. djfrail

    djfrail

    Joined:
    Jan 16, 2014
    Posts:
    124
    I didn't have to modify the 360 profile...
     
  23. mbowen89

    mbowen89

    Joined:
    Jan 21, 2013
    Posts:
    639
    I know, but sometimes they not be correct, etc etc.
     
  24. djfrail

    djfrail

    Joined:
    Jan 16, 2014
    Posts:
    124
    I modified the Playstation4AndroidProfile.cs and this seems to work for my game on Android controlled with the PS4 controller via USB OTG cable. One weird thing is the Options button seems to trigger two things, don't know how to fix.

    Code (CSharp):
    1. using System;
    2.  
    3.  
    4. namespace InControl
    5. {
    6.     // @cond nodoc
    7.     // Tested with Samsung Galaxy Note 2 connected by OTG cable.
    8.     [AutoDiscover]
    9.     public class PlayStation4AndroidProfile : UnityInputDeviceProfile
    10.     {
    11.         public PlayStation4AndroidProfile()
    12.         {
    13.             Name = "PlayStation 4 Controller";
    14.             Meta = "PlayStation 4 Controller on Android";
    15.            
    16.             SupportedPlatforms = new[] {
    17.                 "Android"
    18.             };
    19.            
    20.             JoystickNames = new[] {
    21.                 "Sony Computer Entertainment Wireless Controller"
    22.             };
    23.            
    24.             ButtonMappings = new[] {
    25.                 new InputControlMapping {
    26.                     Handle = "Cross",
    27.                     Target = InputControlType.Action1,
    28.                     Source = Button0
    29.                 },
    30.                 new InputControlMapping {
    31.                     Handle = "Circle",
    32.                     Target = InputControlType.Action2,
    33.                     Source = Button1
    34.                 },
    35.                 new InputControlMapping {
    36.                     Handle = "Square",
    37.                     Target = InputControlType.Action3,
    38.                     Source = Button2
    39.                 },
    40.                 new InputControlMapping {
    41.                     Handle = "Triangle",
    42.                     Target = InputControlType.Action4,
    43.                     Source = Button3
    44.                 },
    45.                 new InputControlMapping {
    46.                     Handle = "Left Bumper",
    47.                     Target = InputControlType.LeftBumper,
    48.                     Source = Button4
    49.                 },
    50.                 new InputControlMapping {
    51.                     Handle = "Right Bumper",
    52.                     Target = InputControlType.RightBumper,
    53.                     Source = Button5
    54.                 },
    55.                 new InputControlMapping {
    56.                     Handle = "Options",
    57.                     Target = InputControlType.Start,
    58.                     //Source = Button7
    59.                     Source = Button10
    60.                 },
    61.                 new InputControlMapping {
    62.                     Handle = "Left Stick Button",
    63.                     Target = InputControlType.LeftStickButton,
    64.                     Source = Button8
    65.                 },
    66.                 new InputControlMapping {
    67.                     Handle = "Right Stick Button",
    68.                     Target = InputControlType.RightStickButton,
    69.                     Source = Button9
    70.                 },
    71.                 new InputControlMapping {
    72.                     Handle = "TouchPad Button",
    73.                     Target = InputControlType.TouchPadTap,
    74.                     Source = Button11
    75.                 },
    76.                
    77.             };
    78.            
    79.             AnalogMappings = new[] {
    80.                 LeftStickLeftMapping( Analog0 ),
    81.                 LeftStickRightMapping( Analog0 ),
    82.                 LeftStickUpMapping( Analog1 ),
    83.                 LeftStickDownMapping( Analog1 ),
    84.                
    85.                 RightStickLeftMapping( Analog2 ),
    86.                 RightStickRightMapping( Analog2 ),
    87.                 RightStickUpMapping( Analog3 ),
    88.                 RightStickDownMapping( Analog3 ),
    89.                
    90.                 DPadLeftMapping( Analog4 ),
    91.                 DPadRightMapping( Analog4 ),
    92.                 //DPadUpMapping( Analog5 ),
    93.                 //DPadDownMapping( Analog5 ),
    94.                
    95.                 new InputControlMapping {
    96.                     Handle = "DPad Up",
    97.                     Target = InputControlType.DPadUp,
    98.                     Source = Analog5,
    99.                     SourceRange = InputRange.ZeroToMinusOne,
    100.                     TargetRange = InputRange.ZeroToOne
    101.                 },
    102.                
    103.                 new InputControlMapping {
    104.                     Handle = "DPad Down",
    105.                     Target = InputControlType.DPadDown,
    106.                     Source = Analog5,
    107.                     SourceRange = InputRange.ZeroToOne,
    108.                     TargetRange = InputRange.ZeroToOne
    109.                 },
    110.                
    111.                
    112.                
    113.                 new InputControlMapping {
    114.                     Handle = "Left Trigger",
    115.                     Target = InputControlType.LeftTrigger,
    116.                     Source = Analog12,
    117.                 },
    118.                 new InputControlMapping {
    119.                     Handle = "Right Trigger",
    120.                     Target = InputControlType.RightTrigger,
    121.                     Source = Analog11,
    122.                     //Invert = true
    123.                 },
    124.                
    125.                
    126.                
    127.             };
    128.         }
    129.     }
    130.     // @endcond
    131. }
    132.  
    133.  
     
  25. DomDom

    DomDom

    Joined:
    Oct 18, 2013
    Posts:
    33
    Hi @pbhogan

    I implemented the Bindings with actionsets, how can I do it properly when having multiple devices on one client?
    I did use InputManager.ActiveDevice, but that doesn't work smoothly, I guess because there won't be both active in one frame update.

    I there a way to bind an actionset to a specific device?
     
    Last edited: Nov 16, 2015
  26. djfrail

    djfrail

    Joined:
    Jan 16, 2014
    Posts:
    124
    Is there a way to make an on-screen button, when pressed/clicked, act like you pressed a key on the keyboard?
     
  27. Mobaiou

    Mobaiou

    Joined:
    Jun 20, 2014
    Posts:
    13
    I used multuplayer example. How is the best way to use the same PlayerActions between scenes? I checked (marked) InControl to be "Dont't destrou on load".
    I tried to keep PlayerActions in a Singleton and put into each player. But when the next scene is loaded I can't move my player. I think I lost my PlayerActions. When I removed the statement from "PlayerActionSet" abstract class worked. But I know this is not a good idea:

    public void Destroy()
    {
    // InputManager.DetachPlayerActionSet( this );
    }

    PS: I am keeping PlayerActions into a singleton, and every scene I instantiate a player with one playeraction.

    public List<PlayerActions> playerActions = new List<PlayerActions>(4);

    public void InstantiateCharacters(Vector3 position){
    GameObject player = PhotonNetwork.Instantiate(characters[Random.Range(0, characters.Length)].name, Vector3.zero, Quaternion.identity, 0);
    player.GetComponent<PlayerController>().Actions = playerActions;
    player.GetComponent<PlayerController>().playerNumber = i;
    }

    }

    ==================================


     
  28. bobmoff

    bobmoff

    Joined:
    Sep 23, 2014
    Posts:
    44
    Hi!

    The asset has been working great until I tried implementing multiplayer support. I store away each device that is connected onto to a player script and then that player is listening to that device's input.

    Moving player 1 works fine separately.
    Moving player 2 works fine separately.

    When move both players at the same time the inputs start to interfere with each other. If I start moving player 1 (holding left stick in the right direction) player 1 starts moving to the right and then start moving player 2 i the left direction (holding left stick in the left direction) both players start moving to the left. Its like the last input that registered takes over both players, but only If the other player is currently moving.

    I am using two wireless 360 controllers on OSX El Capitan connected to the same USB dongle.

    Any help with this issue is appreciated.
     
    DomDom likes this.
  29. DomDom

    DomDom

    Joined:
    Oct 18, 2013
    Posts:
    33
    I have the same problem. I'm using the bindings with Actionset for the PlayerControl and you can acutally assign a device to an actionset, which I thought would solve the problem. But I still have the same Issue was you described.
    I'd appreciate help too, I guess without the bindings it wouldn't be a problem, I've done it before.
     
  30. ObsidianSpire

    ObsidianSpire

    Joined:
    Sep 13, 2013
    Posts:
    48
    Edit: Got an email reply from Patrick. Thanks for the help!
     
    Last edited: Dec 4, 2015
  31. pbhogan

    pbhogan

    Joined:
    Aug 17, 2012
    Posts:
    384
    @DomDom Assigning to PlayerActionSet.Device is supposed to constrain it to only that device... are you using wireless 360 controllers like @bobmoff too? Do the two controllers behave independently in TestInputManager scene as they should?
     
  32. pbhogan

    pbhogan

    Joined:
    Aug 17, 2012
    Posts:
    384
    Just a reminder: Unity Forum notification seem not to work 80% of the time for me and I don't check this thread very often, so if you want a quick reply it is usually best to just e-mail me directly. :)
     
    DomDom likes this.
  33. Devastadus

    Devastadus

    Joined:
    Jan 27, 2015
    Posts:
    80
    Question, i been looking but haven't found a solution. Is there a way to call a PlayerAction triggered by name? So instead of saying

    Code (CSharp):
    1.  
    2. public PlayerActions Actions{get;set;}
    3. void Update(){
    4. if (Actions.AttackButton)
    5.             {              
    6.                 //do attack
    7.             }
    8. }
    9.  
    do something like this

    Code (CSharp):
    1.  
    2.  
    3. // not working code but what i want to do
    4. public PlayerActions Actions{get;set;}
    5. public string button = "AttackButton"
    6.  
    7. void Update(){
    8. if (Actions[button)
    9.             {              
    10.                 //do attack
    11.             }
    12. }
    I want to call the PlayerActions by name. My All my attacks are separate scripts on the Player GameObjects, i would like to pass a variable so they know what PlayerAction to call.
     
  34. pbhogan

    pbhogan

    Joined:
    Aug 17, 2012
    Posts:
    384
    It isn't there right now, but I'll be adding the following to PlayerActionSet.cs in a future update which should allow you to do that. You can add it to the class yourself for the time being until it lands in the update:

    Code (CSharp):
    1.  
    2. public PlayerAction this[ string actionName ]
    3. {
    4.     get
    5.     {
    6.         PlayerAction action;
    7.         if (actionsByName.TryGetValue( actionName, out action ))
    8.         {
    9.             return action;
    10.         }
    11.         throw new KeyNotFoundException( "Action '" + actionName + "' does not exist in this action set." );
    12.     }
    13. }
    14.  
     
  35. Devastadus

    Devastadus

    Joined:
    Jan 27, 2015
    Posts:
    80
    Just what i needed thanks
     
  36. bluntgames

    bluntgames

    Joined:
    Jan 18, 2012
    Posts:
    22
    Hey!
    I'm having a problem with using the new wireless adapter for the Xbox One controller on my Windows7.
    It works via USB but the mapping changes when using it wireless :(

    I'm going to hack in a quick fix myself but I thought I'd let you know.
     
  37. pbhogan

    pbhogan

    Joined:
    Aug 17, 2012
    Posts:
    384
    Does the joystick name change also? If you have a working profile, you are welcome to send it to me for inclusion in future releases.

    You could also turn in XInput support, which might actually work better anyway and should support both wired and wireless mode.
     
  38. Mogulbasher

    Mogulbasher

    Joined:
    Feb 26, 2014
    Posts:
    42
    Quick Question. Is there a way to disable certain controllers selectively. Lets say a user has a steering wheel and a controller plugged in. I have created a pop up when the user selects controller mode over mouse and keyboard mode which asks the user to press A on their controller. Having done so I want to disable all other hardware such as the steering wheel from sending inputs to the screen. The reason is that when players are using a controller and have a steering wheel plugged in all our sliders in the UI start moving around as soon as they are highlighted by the controller since the game is still receiving inputs from a wheel that is not centered. Thanks
     
  39. pbhogan

    pbhogan

    Joined:
    Aug 17, 2012
    Posts:
    384
    No, but you can do the inverse. Save the device reference and query it directly instead of using InputManager.ActiveDevice

    If you're using the bindings API, you can assign it to the Device property of your PlayerActionSet.
     
  40. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    EDIT: (not a customer but I have some questions about InControl)

    Hi there, I'm little bit interested about InControl, mostly related to using touch sticks, buttons, and touch gestures on iOS and Android. I did read website and checked two videos, but I'm still wondering following;

    1. Does InControl have support for touch gestures other than swipes?
    - I'd be interested in pinch and possibly two finger swipes and taps.
    - How about single finger long tap, tap+drag?
    - Or is it possible to extend easily such features if they are not supported?

    2. Like I mentioned, I'm mostly interested in touch part, input mapping would be extra I might need later if at all.
    - How big is the file size on iOS if I only need touch controls?
     
  41. pbhogan

    pbhogan

    Joined:
    Aug 17, 2012
    Posts:
    384
    If all you're really interested in is touch controls, InControl is probably not for you. InControl's primary focus is controllers, so touch controls are focused on creating a virtual controller, not handling general touch input. Currently there is no support for gesture recognition at all (no taps, no swipes, no pinch, multifinger-gestures, etc.) just the basic onscreen controls. Adding support for gestures yourself would be non-trivial. If you need those things you're better off looking for a dedicated touch input asset.

    I have no idea what the file size impact is by the time code goes through IL2CPP and I'm sure it varies from Unity version to version, but I can tell you that the touch parts cannot be extracted from the rest of InControl. It's not intended to be modular in the sense of picking components to include in your project. If anything, the touch components are the optional part.

    My guess is InControl is not right for you.
     
  42. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    pbhogan: OK, thank you for quick reply.

    I checked out a video on your product website, there I saw mapping of 4 directional swipes to joystick axis, that's why I thought I'd ask. I'm not sure if I'd need more options than basic directional swipes, but I might... and at least there is a button, but generic tap support would be nice.

    Also, joystick and buttons look really neat, I'm still considering this asset, although it's always bit hard to predict what you get beforehand.
     
  43. Mogulbasher

    Mogulbasher

    Joined:
    Feb 26, 2014
    Posts:
    42
    So here is my issue, since the other controller is constantly sending commands it is constantly updating active device so even after I hit A on the desired controller in response to the pop up another command comes in from the steering wheel so I cant set my custom device to be the current active device. How do I cpature the device reference. Thanks
     
  44. VertexSoup

    VertexSoup

    Joined:
    Nov 25, 2014
    Posts:
    44
    Hello @pbhogan ,
    this is great asset. I have question before purchase.
    Does this support runtime axis range calibration? If yes, can you please, provide simple example how to perform this operation? I consider using it in current project but looking at git (I know it is not supported officially anymore) I'm missing this functionality.
    Does AssetStore version have it and if so how do I perform this during runtime?
    Thank You.
     
    Last edited: Jan 29, 2016
  45. gameDevi

    gameDevi

    Joined:
    Oct 14, 2015
    Posts:
    155
    Hello ! in need of some advice.

    I've added my PC build to steam and have been able to start the game from my NVidia shield but the PC 360 wired and the NVidia shield are not working.

    Do you have any tips?

    I haven't tried doing a android build and trying that yet. My project is huge and it's taking forever to switch from PC to Android.. its in the process.

    Thanks for your time
     
  46. gameDevi

    gameDevi

    Joined:
    Oct 14, 2015
    Posts:
    155
    Hello ! in need of some advice.

    I've added my PC build to steam and have been able to start the game from my NVidia shield but the PC 360 wired and the NVidia shield are not working.

    Do you have any tips?

    I haven't tried doing a android build and trying that yet. My project is huge and it's taking forever to switch from PC to Android.. its in the process.

    Thanks for your time
     
  47. petak_core

    petak_core

    Joined:
    Nov 19, 2012
    Posts:
    57
    Hello, first of all thank you pbhogan for awesome assets.

    I have a question about mouse and joystick input. Is there any possible way, how to move cursor via joystick right/left stick. For example when I move with my stick to left, cursor move to left too.

    I'm making 2d-click adventure and I would like alternate controls for gamepad.

    Thank you for any help or advice.
     
  48. bocs

    bocs

    Joined:
    May 9, 2009
    Posts:
    413
    Are WebGL builds supported?

    I'm seeing this with an XBox One controller in chrome and firefox.
    *Unity 5.3.2p3

    Chrome almost works, but mappings are all wrong.

     
  49. bocs

    bocs

    Joined:
    May 9, 2009
    Posts:
    413
    Created a WebGL profile that seems to work now.
    *Tested both XBox one, and 360 controller.

    Triggers are on/off...didn't figure out hot to get analog to work.

    XboxWinWebGLProfile
    Code (CSharp):
    1. using System;
    2.  
    3. namespace InControl
    4. {
    5.     // @cond nodoc
    6.     [AutoDiscover]
    7.     public class XboxWinWebGLProfile : UnityInputDeviceProfile
    8.     {
    9.         public XboxWinWebGLProfile()
    10.         {
    11.             Name = "XBox WebGL Controller";
    12.             Meta = "XBox WebGL Controller on Windows";
    13.  
    14.             SupportedPlatforms = new[] {
    15.                 "Windows"
    16.             };
    17.  
    18.             JoystickNames = new[] {
    19.                 "Xbox 360 Controller (XInput STANDARD GAMEPAD)",
    20.                 "xinput"
    21.             };
    22.  
    23.             ButtonMappings = new[] {
    24.                 new InputControlMapping {
    25.                     Handle = "A",
    26.                     Target = InputControlType.Action1,
    27.                     Source = Button0
    28.                 },
    29.                 new InputControlMapping {
    30.                     Handle = "B",
    31.                     Target = InputControlType.Action2,
    32.                     Source = Button1
    33.                 },
    34.                 new InputControlMapping {
    35.                     Handle = "X",
    36.                     Target = InputControlType.Action3,
    37.                     Source = Button2
    38.                 },
    39.                 new InputControlMapping {
    40.                     Handle = "Y",
    41.                     Target = InputControlType.Action4,
    42.                     Source = Button3
    43.                 },
    44.                 new InputControlMapping {
    45.                     Handle = "Left Bumper",
    46.                     Target = InputControlType.LeftBumper,
    47.                     Source = Button4
    48.                 },
    49.                 new InputControlMapping {
    50.                     Handle = "Right Bumper",
    51.                     Target = InputControlType.RightBumper,
    52.                     Source = Button5
    53.                 },
    54.                 new InputControlMapping {
    55.                     Handle = "Left Stick Button",
    56.                     Target = InputControlType.LeftStickButton,
    57.                     Source = Button10
    58.                 },
    59.                 new InputControlMapping {
    60.                     Handle = "Right Stick Button",
    61.                     Target = InputControlType.RightStickButton,
    62.                     Source = Button11
    63.                 },
    64.                 new InputControlMapping {
    65.                     Handle = "View",
    66.                     Target = InputControlType.View,
    67.                     Source = Button8
    68.                 },
    69.                 new InputControlMapping {
    70.                     Handle = "Menu",
    71.                     Target = InputControlType.Menu,
    72.                     Source = Button9
    73.                 }
    74.             };
    75.  
    76.             AnalogMappings = new[] {
    77.                 LeftStickLeftMapping( Analog0 ),
    78.                 LeftStickRightMapping( Analog0 ),
    79.                 LeftStickUpMapping( Analog1 ),
    80.                 LeftStickDownMapping( Analog1 ),
    81.  
    82.                 RightStickLeftMapping( Analog2 ),
    83.                 RightStickRightMapping( Analog2 ),
    84.                 RightStickUpMapping( Analog3 ),
    85.                 RightStickDownMapping( Analog3 ),
    86.  
    87.                 DPadLeftMapping2( Button14 ),
    88.                 DPadRightMapping( Button15 ),              
    89.                 DPadUpMapping2( Button12 ),
    90.                 DPadDownMapping( Button13 ),
    91.                            
    92.                
    93.                 new InputControlMapping {
    94.                     Handle = "Left Trigger",
    95.                     Target = InputControlType.LeftTrigger,
    96.                 Source = Button6
    97.                 },
    98.                 new InputControlMapping {
    99.                     Handle = "Right Trigger",
    100.                     Target = InputControlType.RightTrigger,
    101.                 Source = Button7
    102.                 }
    103.             };
    104.         }
    105.     }
    106.     // @endcond
    107. }
    108.  

    added 2 functions to UnityInputDeviceProfile to get dpad working.
    Code (CSharp):
    1.        
    2. protected static InputControlMapping DPadLeftMapping2( InputControlSource analog )
    3.         {
    4.             return new InputControlMapping {
    5.                 Handle = "DPad Left",
    6.                 Target = InputControlType.DPadLeft,
    7.                 Source = analog,
    8.                 SourceRange = InputRange.ZeroToOne,
    9.                 TargetRange = InputRange.ZeroToOne
    10.             };
    11.         }
    12.        
    13.         protected static InputControlMapping DPadRightMapping2( InputControlSource analog )
    14.         {
    15.             return new InputControlMapping {
    16.                 Handle = "DPad Right",
    17.                 Target = InputControlType.DPadRight,
    18.                 Source = analog,
    19.                 SourceRange = InputRange.ZeroToMinusOne,
    20.                 TargetRange = InputRange.ZeroToOne
    21.             };
    22.         }
     
    VertexSoup likes this.
  50. bocs

    bocs

    Joined:
    May 9, 2009
    Posts:
    413
    Made some WebGL profiles for PS4 controller.
    *Keep in mind I have only tested the profiles on Win 7, Chrome (48.0.2564.109), Firefox (44.0.2)

    Code (CSharp):
    1. using System;
    2.  
    3.  
    4. namespace InControl
    5. {
    6.     // @cond nodoc
    7.     [AutoDiscover]
    8.     public class PlayStation4WebGLChromeProfile : UnityInputDeviceProfile
    9.     {
    10.         public PlayStation4WebGLChromeProfile()
    11.         {
    12.             Name = "PlayStation 4 Controller (Chrome WebGL)";
    13.             Meta = "PlayStation 4 Controller on WebGL";
    14.  
    15.             SupportedPlatforms = new[] {
    16.                 "Windows"
    17.             };
    18.  
    19.             JoystickNames = new[] {
    20.                 "Wireless Controller (STANDARD GAMEPAD Vendor: 054c Product: 05c4standard"
    21.             };
    22.  
    23.             ButtonMappings = new[] {
    24.                 new InputControlMapping {
    25.                     Handle = "A",
    26.                     Target = InputControlType.Action1,
    27.                 Source = Button0
    28.                 },
    29.                 new InputControlMapping {
    30.                     Handle = "B",
    31.                     Target = InputControlType.Action2,
    32.                 Source = Button1
    33.                 },
    34.                 new InputControlMapping {
    35.                     Handle = "X",
    36.                     Target = InputControlType.Action3,
    37.                 Source = Button2
    38.                 },
    39.                 new InputControlMapping {
    40.                     Handle = "Y",
    41.                     Target = InputControlType.Action4,
    42.                 Source = Button3
    43.                 },
    44.                 new InputControlMapping {
    45.                     Handle = "Left Bumper",
    46.                     Target = InputControlType.LeftBumper,
    47.                     Source = Button4
    48.                 },
    49.                 new InputControlMapping {
    50.                     Handle = "Right Bumper",
    51.                     Target = InputControlType.RightBumper,
    52.                     Source = Button5
    53.                 },
    54.                 new InputControlMapping {
    55.                     Handle = "Left Stick Button",
    56.                     Target = InputControlType.LeftStickButton,
    57.                     Source = Button10
    58.                 },
    59.                 new InputControlMapping {
    60.                     Handle = "Right Stick Button",
    61.                     Target = InputControlType.RightStickButton,
    62.                     Source = Button11
    63.                 },
    64.                 new InputControlMapping {
    65.                     Handle = "View",
    66.                     Target = InputControlType.View,
    67.                     Source = Button8
    68.                 },
    69.                 new InputControlMapping {
    70.                     Handle = "Menu",
    71.                     Target = InputControlType.Menu,
    72.                     Source = Button9
    73.                 }
    74.             };
    75.  
    76.             AnalogMappings = new[] {
    77.                 LeftStickLeftMapping( Analog0 ),
    78.                 LeftStickRightMapping( Analog0 ),
    79.                 LeftStickUpMapping( Analog1 ),
    80.                 LeftStickDownMapping( Analog1 ),
    81.  
    82.                 RightStickLeftMapping( Analog2 ),
    83.                 RightStickRightMapping( Analog2 ),
    84.                 RightStickUpMapping( Analog3 ),
    85.                 RightStickDownMapping( Analog3 ),
    86.  
    87.                 DPadLeftMapping2( Button14 ),
    88.                 DPadRightMapping( Button15 ),              
    89.                 DPadUpMapping2( Button12 ),
    90.                 DPadDownMapping( Button13 ),
    91.                            
    92.                
    93.                 new InputControlMapping {
    94.                     Handle = "Left Trigger",
    95.                     Target = InputControlType.LeftTrigger,
    96.                 Source = Button6
    97.                 },
    98.                 new InputControlMapping {
    99.                     Handle = "Right Trigger",
    100.                     Target = InputControlType.RightTrigger,
    101.                 Source = Button7
    102.                 }
    103.             };
    104.         }
    105.     }
    106.     // @endcond
    107. }
    108.  

    Code (CSharp):
    1. using System;
    2.  
    3.  
    4. namespace InControl
    5. {
    6.     // @cond nodoc
    7.     [AutoDiscover]
    8.     public class PlayStation4WebGLFirefoxProfile : UnityInputDeviceProfile
    9.     {
    10.         public PlayStation4WebGLFirefoxProfile()
    11.         {
    12.             Name = "PlayStation 4 Controller (Firefox WebGL)";
    13.             Meta = "PlayStation 4 Controller on WebGL";
    14.  
    15.             SupportedPlatforms = new[] {
    16.                 "Windows"
    17.             };
    18.  
    19.             JoystickNames = new[] {
    20.                 "054c-05c4-Wireless Controller"
    21.             };
    22.  
    23.             ButtonMappings = new[] {
    24.                 new InputControlMapping {
    25.                     Handle = "A",
    26.                     Target = InputControlType.Action1,
    27.                 Source = Button1
    28.                 },
    29.                 new InputControlMapping {
    30.                     Handle = "B",
    31.                     Target = InputControlType.Action2,
    32.                 Source = Button2
    33.                 },
    34.                 new InputControlMapping {
    35.                     Handle = "X",
    36.                     Target = InputControlType.Action3,
    37.                 Source = Button0
    38.                 },
    39.                 new InputControlMapping {
    40.                     Handle = "Y",
    41.                     Target = InputControlType.Action4,
    42.                 Source = Button3
    43.                 },
    44.                 new InputControlMapping {
    45.                     Handle = "Left Bumper",
    46.                     Target = InputControlType.LeftBumper,
    47.                     Source = Button4
    48.                 },
    49.                 new InputControlMapping {
    50.                     Handle = "Right Bumper",
    51.                     Target = InputControlType.RightBumper,
    52.                     Source = Button5
    53.                 },
    54.                 new InputControlMapping {
    55.                     Handle = "Left Stick Button",
    56.                     Target = InputControlType.LeftStickButton,
    57.                     Source = Button10
    58.                 },
    59.                 new InputControlMapping {
    60.                     Handle = "Right Stick Button",
    61.                     Target = InputControlType.RightStickButton,
    62.                     Source = Button11
    63.                 },
    64.                 new InputControlMapping {
    65.                     Handle = "View",
    66.                     Target = InputControlType.View,
    67.                     Source = Button8
    68.                 },
    69.                 new InputControlMapping {
    70.                     Handle = "Menu",
    71.                     Target = InputControlType.Menu,
    72.                     Source = Button9
    73.                 }
    74.             };
    75.  
    76.             AnalogMappings = new[] {
    77.                 LeftStickLeftMapping( Analog0 ),
    78.                 LeftStickRightMapping( Analog0 ),
    79.                 LeftStickUpMapping( Analog1 ),
    80.                 LeftStickDownMapping( Analog1 ),
    81.  
    82.                 RightStickLeftMapping( Analog2 ),
    83.                 RightStickRightMapping( Analog2 ),
    84.                 RightStickUpMapping( Analog5 ),
    85.                 RightStickDownMapping( Analog5 ),
    86.  
    87.                 DPadLeftMapping2( Button16 ),
    88.                 DPadRightMapping( Button17 ),              
    89.                 DPadUpMapping2( Button14 ),
    90.                 DPadDownMapping( Button15 ),
    91.                            
    92.                
    93.                 new InputControlMapping {
    94.                     Handle = "Left Trigger",
    95.                     Target = InputControlType.LeftTrigger,
    96.                 Source = Button6
    97.                 },
    98.                 new InputControlMapping {
    99.                     Handle = "Right Trigger",
    100.                     Target = InputControlType.RightTrigger,
    101.                 Source = Button7
    102.                 }
    103.             };
    104.         }
    105.     }
    106.     // @endcond
    107. }
    108.  
     
    VertexSoup likes this.