1
\$\begingroup\$

So, according to some documentation I found, the Xbox controller on Mac does not return Dpad presses as vertical/horizontal axes:

enter image description here

As you can see, the Dpad is only recognized as buttons 5, 6, 7, and 8, and not as horizontal/vertical axes. For my character's movement, I just created code that returns 1 or -1 for axis depending on the button pressed. It works perfectly fine. But then I found another problem: UI navigation.

I can't navigate my menus with the Dpad on Mac because the the EventSystem is expecting navigation via horizontal/vertical axes, which the Dpad is not providing.

Is there any way I can turn these Dpad button presses into real horizontal/vertical axes in Unity's Input system? Or is there something else I can do to make UI navigation happen on a Mac, with the Dpad?

\$\endgroup\$
3
  • \$\begingroup\$ Does assigning these buttons as the positive & negative buttons of an axis in the Input Manager, the same way the defaults are set up for the keyboard arrow keys, not work in this situation? \$\endgroup\$
    – DMGregory
    Commented Aug 31, 2017 at 9:57
  • \$\begingroup\$ @DMGregory That does work, it completely slipped my mind, thank you. It does, however, introduce an issue where the specified buttons "overlap" with those of other platforms. "joystick button 7" is Dpad for left, but on Windows it's also the Start button. I'm not sure how to get around this. \$\endgroup\$
    – Andrio
    Commented Sep 1, 2017 at 0:32
  • \$\begingroup\$ Myself, I usually create two copies of the Input Manager data file and manually swap them out based on the platform I'm building for. There are very likely more robust solutions through. ;) \$\endgroup\$
    – DMGregory
    Commented Sep 1, 2017 at 0:42

1 Answer 1

0
\$\begingroup\$

Nowadays/since MacOS 11 use GCBoxGamepad

example:

#import <GameController/GCController.h>
#import <GameController/GCExtendedGamepad.h>
#import <GameController/GCXboxGamepad.h>
#import <GameController/GCControllerButtonInput.h>
#import <GameController/GCControllerDirectionPad.h>
#import <GameController/GCControllerAxisInput.h>

- (void) checkController {
  int n = (int)GCController.controllers.count;
  
  if( n ) {
    // there's a controller. poll input.
    GCController *controller = GCController.controllers[ 0 ];
    
    //info( "Class type %s", control.extendedGamepad.className.UTF8String );
    if( [controller.extendedGamepad isKindOfClass:[GCXboxGamepad class]] ) {
      //info( "It's an xbox controller" );
      GCXboxGamepad *xboxController = (GCXboxGamepad*)controller.extendedGamepad;
      
      if( xboxController.buttonA.pressed ) {
        info( "you pushed A!" );
      }
      if( xboxController.buttonB.pressed ) {
        info( "you pushed B!" );
      }
      if( xboxController.buttonX.pressed ) {
        info( "you pushed X!" );
      }
      if( xboxController.buttonY.pressed ) {
        info( "you pushed Y!" );
      }
      
      
      if( float x = xboxController.leftThumbstick.xAxis.value ) {
        info( "xAxis %f", x );
      }
      
    }
  }
}

```
\$\endgroup\$
2
  • \$\begingroup\$ This doesn't look like Unity code... \$\endgroup\$
    – DMGregory
    Commented Aug 26 at 11:35
  • \$\begingroup\$ I don't think Unity has added GCController/GCKeyboard in as of yet, so I think you'd have to do straight Objective-C like this if you wanted to use those API's yourself \$\endgroup\$
    – bobobobo
    Commented Aug 26 at 14:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .