// This file is provided under The MIT License as part of Steamworks.NET. // Copyright (c) 2013-2019 Riley Labrecque // Please see the included LICENSE.txt for additional information. // This file is automatically generated. // Changes to this file will be reverted when you update Steamworks.NET #if UNITY_ANDROID || UNITY_IOS || UNITY_TIZEN || UNITY_TVOS || UNITY_WEBGL || UNITY_WSA || UNITY_PS4 || UNITY_WII || UNITY_XBOXONE || UNITY_SWITCH #define DISABLESTEAMWORKS #endif #if !DISABLESTEAMWORKS using System.Runtime.InteropServices; using IntPtr = System.IntPtr; namespace Steamworks { public static class SteamController { /// /// Init and Shutdown must be called when starting/ending use of this interface /// public static bool Init() { InteropHelp.TestIfAvailableClient(); return NativeMethods.ISteamController_Init(CSteamAPIContext.GetSteamController()); } public static bool Shutdown() { InteropHelp.TestIfAvailableClient(); return NativeMethods.ISteamController_Shutdown(CSteamAPIContext.GetSteamController()); } /// /// Synchronize API state with the latest Steam Controller inputs available. This /// is performed automatically by SteamAPI_RunCallbacks, but for the absolute lowest /// possible latency, you call this directly before reading controller state. This must /// be called from somewhere before GetConnectedControllers will return any handles /// public static void RunFrame() { InteropHelp.TestIfAvailableClient(); NativeMethods.ISteamController_RunFrame(CSteamAPIContext.GetSteamController()); } /// /// Enumerate currently connected controllers /// handlesOut should point to a STEAM_CONTROLLER_MAX_COUNT sized array of ControllerHandle_t handles /// Returns the number of handles written to handlesOut /// public static int GetConnectedControllers(ControllerHandle_t[] handlesOut) { InteropHelp.TestIfAvailableClient(); if (handlesOut != null && handlesOut.Length != Constants.STEAM_CONTROLLER_MAX_COUNT) { throw new System.ArgumentException("handlesOut must be the same size as Constants.STEAM_CONTROLLER_MAX_COUNT!"); } return NativeMethods.ISteamController_GetConnectedControllers(CSteamAPIContext.GetSteamController(), handlesOut); } /// /// ----------------------------------------------------------------------------- /// ACTION SETS /// ----------------------------------------------------------------------------- /// Lookup the handle for an Action Set. Best to do this once on startup, and store the handles for all future API calls. /// public static ControllerActionSetHandle_t GetActionSetHandle(string pszActionSetName) { InteropHelp.TestIfAvailableClient(); using (var pszActionSetName2 = new InteropHelp.UTF8StringHandle(pszActionSetName)) { return (ControllerActionSetHandle_t)NativeMethods.ISteamController_GetActionSetHandle(CSteamAPIContext.GetSteamController(), pszActionSetName2); } } /// /// Reconfigure the controller to use the specified action set (ie 'Menu', 'Walk' or 'Drive') /// This is cheap, and can be safely called repeatedly. It's often easier to repeatedly call it in /// your state loops, instead of trying to place it in all of your state transitions. /// public static void ActivateActionSet(ControllerHandle_t controllerHandle, ControllerActionSetHandle_t actionSetHandle) { InteropHelp.TestIfAvailableClient(); NativeMethods.ISteamController_ActivateActionSet(CSteamAPIContext.GetSteamController(), controllerHandle, actionSetHandle); } public static ControllerActionSetHandle_t GetCurrentActionSet(ControllerHandle_t controllerHandle) { InteropHelp.TestIfAvailableClient(); return (ControllerActionSetHandle_t)NativeMethods.ISteamController_GetCurrentActionSet(CSteamAPIContext.GetSteamController(), controllerHandle); } /// /// ACTION SET LAYERS /// public static void ActivateActionSetLayer(ControllerHandle_t controllerHandle, ControllerActionSetHandle_t actionSetLayerHandle) { InteropHelp.TestIfAvailableClient(); NativeMethods.ISteamController_ActivateActionSetLayer(CSteamAPIContext.GetSteamController(), controllerHandle, actionSetLayerHandle); } public static void DeactivateActionSetLayer(ControllerHandle_t controllerHandle, ControllerActionSetHandle_t actionSetLayerHandle) { InteropHelp.TestIfAvailableClient(); NativeMethods.ISteamController_DeactivateActionSetLayer(CSteamAPIContext.GetSteamController(), controllerHandle, actionSetLayerHandle); } public static void DeactivateAllActionSetLayers(ControllerHandle_t controllerHandle) { InteropHelp.TestIfAvailableClient(); NativeMethods.ISteamController_DeactivateAllActionSetLayers(CSteamAPIContext.GetSteamController(), controllerHandle); } /// /// Enumerate currently active layers /// handlesOut should point to a STEAM_CONTROLLER_MAX_ACTIVE_LAYERS sized array of ControllerActionSetHandle_t handles. /// Returns the number of handles written to handlesOut /// public static int GetActiveActionSetLayers(ControllerHandle_t controllerHandle, ControllerActionSetHandle_t[] handlesOut) { InteropHelp.TestIfAvailableClient(); if (handlesOut != null && handlesOut.Length != Constants.STEAM_CONTROLLER_MAX_ACTIVE_LAYERS) { throw new System.ArgumentException("handlesOut must be the same size as Constants.STEAM_CONTROLLER_MAX_ACTIVE_LAYERS!"); } return NativeMethods.ISteamController_GetActiveActionSetLayers(CSteamAPIContext.GetSteamController(), controllerHandle, handlesOut); } /// /// ----------------------------------------------------------------------------- /// ACTIONS /// ----------------------------------------------------------------------------- /// Lookup the handle for a digital action. Best to do this once on startup, and store the handles for all future API calls. /// public static ControllerDigitalActionHandle_t GetDigitalActionHandle(string pszActionName) { InteropHelp.TestIfAvailableClient(); using (var pszActionName2 = new InteropHelp.UTF8StringHandle(pszActionName)) { return (ControllerDigitalActionHandle_t)NativeMethods.ISteamController_GetDigitalActionHandle(CSteamAPIContext.GetSteamController(), pszActionName2); } } /// /// Returns the current state of the supplied digital game action /// public static ControllerDigitalActionData_t GetDigitalActionData(ControllerHandle_t controllerHandle, ControllerDigitalActionHandle_t digitalActionHandle) { InteropHelp.TestIfAvailableClient(); return NativeMethods.ISteamController_GetDigitalActionData(CSteamAPIContext.GetSteamController(), controllerHandle, digitalActionHandle); } /// /// Get the origin(s) for a digital action within an action set. Returns the number of origins supplied in originsOut. Use this to display the appropriate on-screen prompt for the action. /// originsOut should point to a STEAM_CONTROLLER_MAX_ORIGINS sized array of EControllerActionOrigin handles. The EControllerActionOrigin enum will get extended as support for new controller controllers gets added to /// the Steam client and will exceed the values from this header, please check bounds if you are using a look up table. /// public static int GetDigitalActionOrigins(ControllerHandle_t controllerHandle, ControllerActionSetHandle_t actionSetHandle, ControllerDigitalActionHandle_t digitalActionHandle, EControllerActionOrigin[] originsOut) { InteropHelp.TestIfAvailableClient(); if (originsOut != null && originsOut.Length != Constants.STEAM_CONTROLLER_MAX_ORIGINS) { throw new System.ArgumentException("originsOut must be the same size as Constants.STEAM_CONTROLLER_MAX_ORIGINS!"); } return NativeMethods.ISteamController_GetDigitalActionOrigins(CSteamAPIContext.GetSteamController(), controllerHandle, actionSetHandle, digitalActionHandle, originsOut); } /// /// Lookup the handle for an analog action. Best to do this once on startup, and store the handles for all future API calls. /// public static ControllerAnalogActionHandle_t GetAnalogActionHandle(string pszActionName) { InteropHelp.TestIfAvailableClient(); using (var pszActionName2 = new InteropHelp.UTF8StringHandle(pszActionName)) { return (ControllerAnalogActionHandle_t)NativeMethods.ISteamController_GetAnalogActionHandle(CSteamAPIContext.GetSteamController(), pszActionName2); } } /// /// Returns the current state of these supplied analog game action /// public static ControllerAnalogActionData_t GetAnalogActionData(ControllerHandle_t controllerHandle, ControllerAnalogActionHandle_t analogActionHandle) { InteropHelp.TestIfAvailableClient(); return NativeMethods.ISteamController_GetAnalogActionData(CSteamAPIContext.GetSteamController(), controllerHandle, analogActionHandle); } /// /// Get the origin(s) for an analog action within an action set. Returns the number of origins supplied in originsOut. Use this to display the appropriate on-screen prompt for the action. /// originsOut should point to a STEAM_CONTROLLER_MAX_ORIGINS sized array of EControllerActionOrigin handles. The EControllerActionOrigin enum will get extended as support for new controller controllers gets added to /// the Steam client and will exceed the values from this header, please check bounds if you are using a look up table. /// public static int GetAnalogActionOrigins(ControllerHandle_t controllerHandle, ControllerActionSetHandle_t actionSetHandle, ControllerAnalogActionHandle_t analogActionHandle, EControllerActionOrigin[] originsOut) { InteropHelp.TestIfAvailableClient(); if (originsOut != null && originsOut.Length != Constants.STEAM_CONTROLLER_MAX_ORIGINS) { throw new System.ArgumentException("originsOut must be the same size as Constants.STEAM_CONTROLLER_MAX_ORIGINS!"); } return NativeMethods.ISteamController_GetAnalogActionOrigins(CSteamAPIContext.GetSteamController(), controllerHandle, actionSetHandle, analogActionHandle, originsOut); } /// /// Get a local path to art for on-screen glyph for a particular origin - this call is cheap /// public static string GetGlyphForActionOrigin(EControllerActionOrigin eOrigin) { InteropHelp.TestIfAvailableClient(); return InteropHelp.PtrToStringUTF8(NativeMethods.ISteamController_GetGlyphForActionOrigin(CSteamAPIContext.GetSteamController(), eOrigin)); } /// /// Returns a localized string (from Steam's language setting) for the specified origin - this call is serialized /// public static string GetStringForActionOrigin(EControllerActionOrigin eOrigin) { InteropHelp.TestIfAvailableClient(); return InteropHelp.PtrToStringUTF8(NativeMethods.ISteamController_GetStringForActionOrigin(CSteamAPIContext.GetSteamController(), eOrigin)); } public static void StopAnalogActionMomentum(ControllerHandle_t controllerHandle, ControllerAnalogActionHandle_t eAction) { InteropHelp.TestIfAvailableClient(); NativeMethods.ISteamController_StopAnalogActionMomentum(CSteamAPIContext.GetSteamController(), controllerHandle, eAction); } /// /// Returns raw motion data from the specified controller /// public static ControllerMotionData_t GetMotionData(ControllerHandle_t controllerHandle) { InteropHelp.TestIfAvailableClient(); return NativeMethods.ISteamController_GetMotionData(CSteamAPIContext.GetSteamController(), controllerHandle); } /// /// ----------------------------------------------------------------------------- /// OUTPUTS /// ----------------------------------------------------------------------------- /// Trigger a haptic pulse on a controller /// public static void TriggerHapticPulse(ControllerHandle_t controllerHandle, ESteamControllerPad eTargetPad, ushort usDurationMicroSec) { InteropHelp.TestIfAvailableClient(); NativeMethods.ISteamController_TriggerHapticPulse(CSteamAPIContext.GetSteamController(), controllerHandle, eTargetPad, usDurationMicroSec); } /// /// Trigger a pulse with a duty cycle of usDurationMicroSec / usOffMicroSec, unRepeat times. /// nFlags is currently unused and reserved for future use. /// public static void TriggerRepeatedHapticPulse(ControllerHandle_t controllerHandle, ESteamControllerPad eTargetPad, ushort usDurationMicroSec, ushort usOffMicroSec, ushort unRepeat, uint nFlags) { InteropHelp.TestIfAvailableClient(); NativeMethods.ISteamController_TriggerRepeatedHapticPulse(CSteamAPIContext.GetSteamController(), controllerHandle, eTargetPad, usDurationMicroSec, usOffMicroSec, unRepeat, nFlags); } /// /// Trigger a vibration event on supported controllers. /// public static void TriggerVibration(ControllerHandle_t controllerHandle, ushort usLeftSpeed, ushort usRightSpeed) { InteropHelp.TestIfAvailableClient(); NativeMethods.ISteamController_TriggerVibration(CSteamAPIContext.GetSteamController(), controllerHandle, usLeftSpeed, usRightSpeed); } /// /// Set the controller LED color on supported controllers. /// public static void SetLEDColor(ControllerHandle_t controllerHandle, byte nColorR, byte nColorG, byte nColorB, uint nFlags) { InteropHelp.TestIfAvailableClient(); NativeMethods.ISteamController_SetLEDColor(CSteamAPIContext.GetSteamController(), controllerHandle, nColorR, nColorG, nColorB, nFlags); } /// /// ----------------------------------------------------------------------------- /// Utility functions availible without using the rest of Steam Input API /// ----------------------------------------------------------------------------- /// Invokes the Steam overlay and brings up the binding screen if the user is using Big Picture Mode /// If the user is not in Big Picture Mode it will open up the binding in a new window /// public static bool ShowBindingPanel(ControllerHandle_t controllerHandle) { InteropHelp.TestIfAvailableClient(); return NativeMethods.ISteamController_ShowBindingPanel(CSteamAPIContext.GetSteamController(), controllerHandle); } /// /// Returns the input type for a particular handle /// public static ESteamInputType GetInputTypeForHandle(ControllerHandle_t controllerHandle) { InteropHelp.TestIfAvailableClient(); return NativeMethods.ISteamController_GetInputTypeForHandle(CSteamAPIContext.GetSteamController(), controllerHandle); } /// /// Returns the associated controller handle for the specified emulated gamepad - can be used with the above 2 functions /// to identify controllers presented to your game over Xinput. Returns 0 if the Xinput index isn't associated with Steam Input /// public static ControllerHandle_t GetControllerForGamepadIndex(int nIndex) { InteropHelp.TestIfAvailableClient(); return (ControllerHandle_t)NativeMethods.ISteamController_GetControllerForGamepadIndex(CSteamAPIContext.GetSteamController(), nIndex); } /// /// Returns the associated gamepad index for the specified controller, if emulating a gamepad or -1 if not associated with an Xinput index /// public static int GetGamepadIndexForController(ControllerHandle_t ulControllerHandle) { InteropHelp.TestIfAvailableClient(); return NativeMethods.ISteamController_GetGamepadIndexForController(CSteamAPIContext.GetSteamController(), ulControllerHandle); } /// /// Returns a localized string (from Steam's language setting) for the specified Xbox controller origin. /// public static string GetStringForXboxOrigin(EXboxOrigin eOrigin) { InteropHelp.TestIfAvailableClient(); return InteropHelp.PtrToStringUTF8(NativeMethods.ISteamController_GetStringForXboxOrigin(CSteamAPIContext.GetSteamController(), eOrigin)); } /// /// Get a local path to art for on-screen glyph for a particular Xbox controller origin. /// public static string GetGlyphForXboxOrigin(EXboxOrigin eOrigin) { InteropHelp.TestIfAvailableClient(); return InteropHelp.PtrToStringUTF8(NativeMethods.ISteamController_GetGlyphForXboxOrigin(CSteamAPIContext.GetSteamController(), eOrigin)); } /// /// Get the equivalent ActionOrigin for a given Xbox controller origin this can be chained with GetGlyphForActionOrigin to provide future proof glyphs for /// non-Steam Input API action games. Note - this only translates the buttons directly and doesn't take into account any remapping a user has made in their configuration /// public static EControllerActionOrigin GetActionOriginFromXboxOrigin(ControllerHandle_t controllerHandle, EXboxOrigin eOrigin) { InteropHelp.TestIfAvailableClient(); return NativeMethods.ISteamController_GetActionOriginFromXboxOrigin(CSteamAPIContext.GetSteamController(), controllerHandle, eOrigin); } /// /// Convert an origin to another controller type - for inputs not present on the other controller type this will return k_EControllerActionOrigin_None /// public static EControllerActionOrigin TranslateActionOrigin(ESteamInputType eDestinationInputType, EControllerActionOrigin eSourceOrigin) { InteropHelp.TestIfAvailableClient(); return NativeMethods.ISteamController_TranslateActionOrigin(CSteamAPIContext.GetSteamController(), eDestinationInputType, eSourceOrigin); } /// /// Get the binding revision for a given device. Returns false if the handle was not valid or if a mapping is not yet loaded for the device /// public static bool GetControllerBindingRevision(ControllerHandle_t controllerHandle, out int pMajor, out int pMinor) { InteropHelp.TestIfAvailableClient(); return NativeMethods.ISteamController_GetControllerBindingRevision(CSteamAPIContext.GetSteamController(), controllerHandle, out pMajor, out pMinor); } } } #endif // !DISABLESTEAMWORKS