using Facepunch.Steamworks.Data; using System.Collections.Generic; namespace Facepunch.Steamworks { public class SteamInput : SteamClientClass { internal static ISteamInput Internal => Interface as ISteamInput; internal override void InitializeInterface( bool server ) { SetInterface( server, new ISteamInput( server ) ); } internal const int STEAM_CONTROLLER_MAX_COUNT = 16; /// /// You shouldn't really need to call this because it get called by RunCallbacks on SteamClient /// but Valve think it might be a nice idea if you call it right before you get input info - /// just to make sure the info you're getting is 100% up to date. /// public static void RunFrame() { Internal.RunFrame(); } static readonly InputHandle_t[] queryArray = new InputHandle_t[STEAM_CONTROLLER_MAX_COUNT]; /// /// Return a list of connected controllers. /// public static IEnumerable Controllers { get { var num = Internal.GetConnectedControllers( queryArray ); for ( int i = 0; i < num; i++ ) { yield return new Controller( queryArray[i] ); } } } /// /// Return an absolute path to the PNG image glyph for the provided digital action name. The current /// action set in use for the controller will be used for the lookup. You should cache the result and /// maintain your own list of loaded PNG assets. /// /// /// /// public static string GetDigitalActionGlyph( Controller controller, string action ) { InputActionOrigin origin = InputActionOrigin.None; Internal.GetDigitalActionOrigins( controller.Handle, Internal.GetCurrentActionSet(controller.Handle), GetDigitalActionHandle(action), ref origin ); return Internal.GetGlyphForActionOrigin(origin); } internal static Dictionary DigitalHandles = new Dictionary(); internal static InputDigitalActionHandle_t GetDigitalActionHandle( string name ) { if ( DigitalHandles.TryGetValue( name, out var val ) ) return val; val = Internal.GetDigitalActionHandle( name ); DigitalHandles.Add( name, val ); return val; } internal static Dictionary AnalogHandles = new Dictionary(); internal static InputAnalogActionHandle_t GetAnalogActionHandle( string name ) { if ( AnalogHandles.TryGetValue( name, out var val ) ) return val; val = Internal.GetAnalogActionHandle( name ); AnalogHandles.Add( name, val ); return val; } internal static Dictionary ActionSets = new Dictionary(); internal static InputActionSetHandle_t GetActionSetHandle( string name ) { if ( ActionSets.TryGetValue( name, out var val ) ) return val; val = Internal.GetActionSetHandle( name ); ActionSets.Add( name, val ); return val; } } }