From d19f420a244a894fff76f38bc70dc4aca88e1107 Mon Sep 17 00:00:00 2001 From: Herman Groenenboom Date: Fri, 7 Apr 2023 10:54:45 +0200 Subject: [PATCH] Add bindings for retrieving InputActionOrigins for a Controller. --- Facepunch.Steamworks/Structs/Controller.cs | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/Facepunch.Steamworks/Structs/Controller.cs b/Facepunch.Steamworks/Structs/Controller.cs index f694ecd..8acea94 100644 --- a/Facepunch.Steamworks/Structs/Controller.cs +++ b/Facepunch.Steamworks/Structs/Controller.cs @@ -1,5 +1,6 @@ using Steamworks.Data; using System.Collections.Generic; +using System.Linq; using System.Runtime.InteropServices; namespace Steamworks @@ -30,6 +31,40 @@ namespace Steamworks public void ActivateLayer( string layer ) => SteamInput.Internal.ActivateActionSetLayer( Handle, SteamInput.Internal.GetActionSetHandle( layer ) ); public void ClearLayers() => SteamInput.Internal.DeactivateAllActionSetLayers( Handle ); + #region Action Origins + + internal const int STEAM_INPUT_MAX_ORIGINS = 8; + internal InputActionSetHandle_t ActionSetHandle => SteamInput.Internal.GetCurrentActionSet( Handle ); + + /// + /// Get the origin(s) for an analog action within an action set. + /// Use this to display the appropriate on-screen prompt for the action. + /// + /// This is cheap, and Valve recommends you re-gather the origins each frame to update your ingame prompts in case they have changed. + /// + /// + public IEnumerable GetAnalogActionOrigins( string actionName ) + { + InputActionOrigin[] actionOrigins = new InputActionOrigin[STEAM_INPUT_MAX_ORIGINS]; + int numOrigins = SteamInput.Internal.GetAnalogActionOrigins( Handle, ActionSetHandle, SteamInput.Internal.GetAnalogActionHandle( actionName ), ref actionOrigins[0] ); + return actionOrigins.Take( numOrigins ); + } + + /// + /// Get the origin(s) for a digital action within an action set. + /// Use this to display the appropriate on-screen prompt for the action. + /// + /// This is cheap, and Valve recommends you re-gather the origins each frame to update your ingame prompts in case they have changed. + /// + /// + public IEnumerable GetDigitalActionOrigins( string actionName ) + { + InputActionOrigin[] actionOrigins = new InputActionOrigin[STEAM_INPUT_MAX_ORIGINS]; + int numOrigins = SteamInput.Internal.GetDigitalActionOrigins( Handle, ActionSetHandle, SteamInput.Internal.GetDigitalActionHandle( actionName ), ref actionOrigins[0] ); + return actionOrigins.Take( numOrigins ); + } + + #endregion Action Origins /// /// Returns the current state of the supplied digital game action