docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class AndroidGamepad

    Gamepad on Android. Comprises all types of gamepads supported on Android.

    Inheritance
    object
    InputControl
    InputDevice
    Gamepad
    AndroidGamepad
    AndroidGamepadWithDpadAxes
    AndroidGamepadWithDpadButtons
    Implements
    IDualMotorRumble
    IHaptics
    Inherited Members
    Gamepad.buttonWest
    Gamepad.buttonNorth
    Gamepad.buttonSouth
    Gamepad.buttonEast
    Gamepad.leftStickButton
    Gamepad.rightStickButton
    Gamepad.startButton
    Gamepad.selectButton
    Gamepad.dpad
    Gamepad.leftShoulder
    Gamepad.rightShoulder
    Gamepad.leftStick
    Gamepad.rightStick
    Gamepad.leftTrigger
    Gamepad.rightTrigger
    Gamepad.aButton
    Gamepad.bButton
    Gamepad.xButton
    Gamepad.yButton
    Gamepad.triangleButton
    Gamepad.squareButton
    Gamepad.circleButton
    Gamepad.crossButton
    Gamepad.this[GamepadButton]
    Gamepad.current
    Gamepad.all
    Gamepad.FinishSetup()
    Gamepad.MakeCurrent()
    Gamepad.OnAdded()
    Gamepad.OnRemoved()
    Gamepad.PauseHaptics()
    Gamepad.ResumeHaptics()
    Gamepad.ResetHaptics()
    Gamepad.SetMotorSpeeds(float, float)
    InputDevice.InvalidDeviceId
    InputDevice.description
    InputDevice.enabled
    InputDevice.canRunInBackground
    InputDevice.added
    InputDevice.remote
    InputDevice.native
    InputDevice.updateBeforeRender
    InputDevice.deviceId
    InputDevice.lastUpdateTime
    InputDevice.wasUpdatedThisFrame
    InputDevice.allControls
    InputDevice.valueType
    InputDevice.valueSizeInBytes
    InputDevice.ReadValueFromBufferAsObject(void*, int)
    InputDevice.ReadValueFromStateAsObject(void*)
    InputDevice.ReadValueFromStateIntoBuffer(void*, void*, int)
    InputDevice.CompareValue(void*, void*)
    InputDevice.OnConfigurationChanged()
    InputDevice.ExecuteCommand<TCommand>(ref TCommand)
    InputDevice.ExecuteCommand(InputDeviceCommand*)
    InputControl.name
    InputControl.displayName
    InputControl.shortDisplayName
    InputControl.path
    InputControl.layout
    InputControl.variants
    InputControl.device
    InputControl.parent
    InputControl.children
    InputControl.usages
    InputControl.aliases
    InputControl.stateBlock
    InputControl.noisy
    InputControl.synthetic
    InputControl.this[string]
    InputControl.magnitude
    InputControl.ToString()
    InputControl.EvaluateMagnitude()
    InputControl.EvaluateMagnitude(void*)
    InputControl.WriteValueFromBufferIntoState(void*, int, void*)
    InputControl.WriteValueFromObjectIntoState(object, void*)
    InputControl.TryGetChildControl(string)
    InputControl.TryGetChildControl<TControl>(string)
    InputControl.GetChildControl(string)
    InputControl.GetChildControl<TControl>(string)
    InputControl.RefreshConfigurationIfNeeded()
    InputControl.RefreshConfiguration()
    InputControl.m_StateBlock
    InputControl.currentStatePtr
    InputControl.previousFrameStatePtr
    InputControl.defaultStatePtr
    InputControl.noiseMaskPtr
    InputControl.stateOffsetRelativeToDeviceRoot
    InputControl.optimizedControlDataType
    InputControl.CalculateOptimizedControlDataType()
    InputControl.ApplyParameterChanges()
    Namespace: UnityEngine.InputSystem.Android
    Assembly: Unity.InputSystem.dll
    Syntax
    public class AndroidGamepad : Gamepad, IDualMotorRumble, IHaptics
    Remarks

    Most of the gamepads:

    • ELAN PLAYSTATION(R)3 Controller
    • My-Power CO.,LTD. PS(R) Controller Adaptor (Following tested and work with: Nvidia Shield TV (OS 9); Galaxy Note 20 Ultra (OS 11); Galaxy S9+ (OS 10.0))
    • Sony Interactive Entertainment Wireless (PS4 DualShock) (Also tested and DOES NOT WORK with Galaxy S9 (OS 8.0); Galaxy S8 (OS 7.0); Xiaomi Mi Note2 (OS 8.0))
    • Xbox Wireless Controller (Xbox One) (Also tested and works on Samsung Galaxy S8 (OS 7.0); Xiaomi Mi Note2 (OS 8.0))
    • NVIDIA Controller v01.03/v01.04
    • (Add more) map buttons in the following way: Left Stick -> AXIS_X(0) / AXIS_Y(1) Right Stick -> AXIS_Z (11) / AXIS_RZ(14) Right Thumb -> KEYCODE_BUTTON_THUMBR(107) Left Thumb -> KEYCODE_BUTTON_THUMBL(106) L1 (Left shoulder) -> KEYCODE_BUTTON_L1(102) R1 (Right shoulder) -> KEYCODE_BUTTON_R1(103) L2 (Left trigger) -> AXIS_BRAKE(23) R2 (Right trigger) -> AXIS_GAS(22) X -> KEYCODE_BUTTON_X(99) Y -> KEYCODE_BUTTON_Y(100) B -> KEYCODE_BUTTON_B(97) A -> KEYCODE_BUTTON_A(96) DPAD -> AXIS_HAT_X(15),AXIS_HAT_Y(16) or KEYCODE_DPAD_LEFT(21), KEYCODE_DPAD_RIGHT(22), KEYCODE_DPAD_UP(19), KEYCODE_DPAD_DOWN(20), Note: On Nvidia Shield Console, L2/R2 additionally invoke key events for AXIS_LTRIGGER, AXIS_RTRIGGER (in addition to AXIS_BRAKE, AXIS_GAS) If you connect gamepad to a phone for L2/R2 only AXIS_BRAKE/AXIS_GAS come. AXIS_LTRIGGER, AXIS_RTRIGGER are not invoked. That's why we map triggers only to AXIS_BRAKE/AXIS_GAS Nvidia Shield also reports KEYCODE_BACK instead of KEYCODE_BUTTON_SELECT, so Options(XboxOne Controller)/View(DualShock)/Select buttons do not work PS4 controller is officially supported from Android 10 and higher (https://playstation.com/en-us/support/hardware/ps4-pair-dualshock-4-wireless-with-sony-xperia-and-android) However, some devices with older OS have fixed PS4 controller support on their drivers this leads to following situation: Some gamepads on Android devices (with same Android number version) might have different mappings For ex., Dualshock, on NVidia Shield Console (OS 8.0) all buttons correctly map according to rules in AndroidGameControllerState when clicking left shoulder it will go to AndroidKeyCode.ButtonL1, rightShoulder -> AndroidKeyCode.ButtonR1, etc But, on Samsung Galaxy S9 (OS 8.0), the mapping is different (Same for Xiaomi Mi Note2 (OS 8.0), Samsung Galaxy S8 (OS 7.0)) when clicking left shoulder it will go to AndroidKeyCode.ButtonY, rightShoulder -> AndroidKeyCode.ButtonZ, etc So even though Android version is 8.0 in both cases, Dualshock will only correctly work on NVidia Shield Console It's obvious that this depends on the driver and not Android OS, thus we can only assume Samsung in this case doesn't properly support Dualshock in their drivers While we can do custom mapping for Samsung, we can never now when will they try to update the driver for Dualshock or some other gamepad

    Implements

    IDualMotorRumble
    IHaptics

    Extension Methods

    InputControlExtensions.CheckStateIsAtDefault(InputControl)
    InputControlExtensions.CheckStateIsAtDefault(InputControl, void*, void*)
    InputControlExtensions.CheckStateIsAtDefaultIgnoringNoise(InputControl)
    InputControlExtensions.CheckStateIsAtDefaultIgnoringNoise(InputControl, void*)
    InputControlExtensions.CompareState(InputControl, void*, void*)
    InputControlExtensions.CompareState(InputControl, void*, void*, void*)
    InputControlExtensions.CompareStateIgnoringNoise(InputControl, void*)
    InputControlExtensions.FindControlsRecursive<TControl>(InputControl, IList<TControl>, Func<TControl, bool>)
    InputControlExtensions.FindInParentChain<TControl>(InputControl)
    InputControlExtensions.GetStatePtrFromStateEvent(InputControl, InputEventPtr)
    InputControlExtensions.HasValueChangeInEvent(InputControl, InputEventPtr)
    InputControlExtensions.HasValueChangeInState(InputControl, void*)
    InputControlExtensions.IsActuated(InputControl, float)
    InputControlExtensions.IsPressed(InputControl, float)
    InputControlExtensions.ReadDefaultValueAsObject(InputControl)
    InputControlExtensions.ReadValueAsObject(InputControl)
    InputControlExtensions.ReadValueFromEventAsObject(InputControl, InputEventPtr)
    InputControlExtensions.ReadValueIntoBuffer(InputControl, void*, int)
    InputControlExtensions.ResetToDefaultStateInEvent(InputControl, InputEventPtr)
    InputControlExtensions.WriteValueFromObjectIntoEvent(InputControl, InputEventPtr, object)
    InputControlExtensions.WriteValueIntoEvent<TValue>(InputControl, TValue, InputEventPtr)
    InputControlExtensions.WriteValueIntoState(InputControl, void*)
    InputControlExtensions.WriteValueIntoState<TValue>(InputControl, TValue, void*)
    InputControlExtensions.CopyState(InputDevice, void*, int)
    InputControlExtensions.CopyState<TState>(InputDevice, out TState)

    Did you find this page useful? Please give it a rating:

    Thanks for rating this page!

    Report a problem on this page

    What kind of problem would you like to report?

    • This page needs code samples
    • Code samples do not work
    • Information is missing
    • Information is incorrect
    • Information is unclear or confusing
    • There is a spelling/grammar error on this page
    • Something else

    Thanks for letting us know! This page has been marked for review based on your feedback.

    If you have time, you can provide more information to help us fix the problem faster.

    Provide more information

    You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:

    You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:

    You've told us there is information missing from this page. Please tell us more about what's missing:

    You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:

    You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:

    You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:

    You've told us this page has a problem. Please tell us more about what's wrong:

    Thank you for helping to make the Unity documentation better!

    Your feedback has been submitted as a ticket for our documentation team to review.

    We are not able to reply to every ticket submitted.

    In This Article
    • Implements
    • Extension Methods
    Back to top
    Copyright © 2024 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)